author | blanchet |
Mon, 22 Aug 2011 15:02:45 +0200 | |
changeset 44396 | 66b9b3fcd608 |
parent 44121 | 44adaa6db327 |
child 44399 | cd1e32b8d4c4 |
permissions | -rw-r--r-- |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
1 |
(* Title: HOL/Tools/ATP/atp_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 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
6 |
Proof reconstruction from ATP proofs. |
33310 | 7 |
*) |
8 |
||
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
9 |
signature ATP_RECONSTRUCT = |
24425
ca97c6f3d9cd
Returning both a "one-line" proof and a structured proof
paulson
parents:
24387
diff
changeset
|
10 |
sig |
43678 | 11 |
type ('a, 'b) ho_term = ('a, 'b) ATP_Problem.ho_term |
43127 | 12 |
type ('a, 'b, 'c) formula = ('a, 'b, 'c) ATP_Problem.formula |
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
13 |
type 'a proof = 'a ATP_Proof.proof |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
14 |
type locality = ATP_Translate.locality |
43033 | 15 |
|
16 |
datatype reconstructor = |
|
17 |
Metis | |
|
43228
2ed2f092e990
obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents:
43212
diff
changeset
|
18 |
Metis_Full_Types | |
2ed2f092e990
obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents:
43212
diff
changeset
|
19 |
Metis_No_Types | |
43033 | 20 |
SMT of string |
21 |
||
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43039
diff
changeset
|
22 |
datatype play = |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43039
diff
changeset
|
23 |
Played of reconstructor * Time.time | |
43033 | 24 |
Trust_Playable of reconstructor * Time.time option| |
43166 | 25 |
Failed_to_Play of reconstructor |
43033 | 26 |
|
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36231
diff
changeset
|
27 |
type minimize_command = string list -> string |
43033 | 28 |
type one_line_params = |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43039
diff
changeset
|
29 |
play * string * (string * locality) list * minimize_command * int * int |
38818
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
30 |
type isar_params = |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
31 |
bool * bool * int * string Symtab.table * int list list * int |
43102 | 32 |
* (string * locality) list vector * int Symtab.table * string proof * thm |
42451
a75fcd103cbb
automatically remove offending facts when faced with an unsound proof -- instead of using the highly inefficient "full_types" option
blanchet
parents:
42449
diff
changeset
|
33 |
val used_facts_in_atp_proof : |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
34 |
Proof.context -> int -> (string * locality) list vector -> string proof |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
35 |
-> (string * locality) list |
42876
e336ef6313aa
more informative message when Sledgehammer finds an unsound proof
blanchet
parents:
42761
diff
changeset
|
36 |
val used_facts_in_unsound_atp_proof : |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
37 |
Proof.context -> int list list -> int -> (string * locality) list vector |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
38 |
-> 'a proof -> string list option |
43033 | 39 |
val uses_typed_helpers : int list -> 'a proof -> bool |
40 |
val one_line_proof_text : one_line_params -> string |
|
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
41 |
val make_tvar : string -> typ |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
42 |
val make_tfree : Proof.context -> string -> typ |
43094 | 43 |
val term_from_atp : |
43678 | 44 |
Proof.context -> bool -> int Symtab.table -> typ option -> (string, string) ho_term |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
45 |
-> term |
43127 | 46 |
val prop_from_atp : |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
47 |
Proof.context -> bool -> int Symtab.table |
43678 | 48 |
-> (string, string, (string, string) ho_term) formula -> term |
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
49 |
val isar_proof_text : |
43062
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
50 |
Proof.context -> bool -> isar_params -> one_line_params -> string |
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
51 |
val proof_text : |
43033 | 52 |
Proof.context -> bool -> isar_params -> one_line_params -> string |
24425
ca97c6f3d9cd
Returning both a "one-line" proof and a structured proof
paulson
parents:
24387
diff
changeset
|
53 |
end; |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
54 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
55 |
structure ATP_Reconstruct : ATP_RECONSTRUCT = |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
56 |
struct |
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
57 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
58 |
open ATP_Util |
38028 | 59 |
open ATP_Problem |
39452 | 60 |
open ATP_Proof |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
61 |
open ATP_Translate |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
62 |
|
43033 | 63 |
datatype reconstructor = |
64 |
Metis | |
|
43228
2ed2f092e990
obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents:
43212
diff
changeset
|
65 |
Metis_Full_Types | |
2ed2f092e990
obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents:
43212
diff
changeset
|
66 |
Metis_No_Types | |
43033 | 67 |
SMT of string |
68 |
||
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43039
diff
changeset
|
69 |
datatype play = |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43039
diff
changeset
|
70 |
Played of reconstructor * Time.time | |
43033 | 71 |
Trust_Playable of reconstructor * Time.time option | |
43166 | 72 |
Failed_to_Play of reconstructor |
43033 | 73 |
|
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36231
diff
changeset
|
74 |
type minimize_command = string list -> string |
43033 | 75 |
type one_line_params = |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43039
diff
changeset
|
76 |
play * string * (string * locality) list * minimize_command * int * int |
38818
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
77 |
type isar_params = |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
78 |
bool * bool * int * string Symtab.table * int list list * int |
43037 | 79 |
* (string * locality) list vector * int Symtab.table * string proof * thm |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36231
diff
changeset
|
80 |
|
42881
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
81 |
val is_typed_helper_name = |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
82 |
String.isPrefix helper_prefix andf String.isSuffix typed_helper_suffix |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
83 |
|
39500 | 84 |
fun find_first_in_list_vector vec key = |
85 |
Vector.foldl (fn (ps, NONE) => AList.lookup (op =) ps key |
|
86 |
| (_, value) => value) NONE vec |
|
87 |
||
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
88 |
val unprefix_fact_number = space_implode "_" o tl o space_explode "_" |
42180
a6c141925a8a
added monomorphization option to Sledgehammer ATPs -- this looks promising but is still off by default
blanchet
parents:
41742
diff
changeset
|
89 |
|
a6c141925a8a
added monomorphization option to Sledgehammer ATPs -- this looks promising but is still off by default
blanchet
parents:
41742
diff
changeset
|
90 |
val vampire_step_prefix = "f" (* grrr... *) |
41203
1393514094d7
fixed more issues with the Vampire output parser, and added support for Vampire's TSTP output (--proof tptp)
blanchet
parents:
41151
diff
changeset
|
91 |
|
42881
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
92 |
val extract_step_number = |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
93 |
Int.fromString o perhaps (try (unprefix vampire_step_prefix)) |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
94 |
|
43481 | 95 |
fun resolve_one_named_fact fact_names s = |
96 |
case try (unprefix fact_prefix) s of |
|
97 |
SOME s' => |
|
98 |
let val s' = s' |> unprefix_fact_number |> unascii_of in |
|
99 |
s' |> find_first_in_list_vector fact_names |> Option.map (pair s') |
|
100 |
end |
|
101 |
| NONE => NONE |
|
102 |
fun resolve_fact _ fact_names (_, SOME ss) = |
|
103 |
map_filter (resolve_one_named_fact fact_names) ss |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
104 |
| resolve_fact facts_offset fact_names (num, NONE) = |
42881
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
105 |
(case extract_step_number num of |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
106 |
SOME j => |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
107 |
let val j = j - facts_offset in |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
108 |
if j > 0 andalso j <= Vector.length fact_names then |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
109 |
Vector.sub (fact_names, j - 1) |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
110 |
else |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
111 |
[] |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
112 |
end |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
113 |
| NONE => []) |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
114 |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
115 |
fun is_fact conjecture_shape = not o null o resolve_fact 0 conjecture_shape |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
116 |
|
43481 | 117 |
fun resolve_one_named_conjecture s = |
118 |
case try (unprefix conjecture_prefix) s of |
|
119 |
SOME s' => Int.fromString s' |
|
120 |
| NONE => NONE |
|
121 |
||
122 |
fun resolve_conjecture _ (_, SOME ss) = |
|
123 |
map_filter resolve_one_named_conjecture ss |
|
42751
f42fd9754724
fixed conjecture resolution bug for Vampire 1.0's TSTP output
blanchet
parents:
42680
diff
changeset
|
124 |
| resolve_conjecture conjecture_shape (num, NONE) = |
42881
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
125 |
case extract_step_number num of |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
126 |
SOME i => (case find_index (exists (curry (op =) i)) conjecture_shape of |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
127 |
~1 => [] |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
128 |
| j => [j]) |
42751
f42fd9754724
fixed conjecture resolution bug for Vampire 1.0's TSTP output
blanchet
parents:
42680
diff
changeset
|
129 |
| NONE => [] |
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
130 |
|
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
131 |
fun is_conjecture conjecture_shape = |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
132 |
not o null o resolve_conjecture conjecture_shape |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
133 |
|
43481 | 134 |
fun is_typed_helper _ (_, SOME ss) = exists is_typed_helper_name ss |
42881
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
135 |
| is_typed_helper typed_helpers (num, NONE) = |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
136 |
(case extract_step_number num of |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
137 |
SOME i => member (op =) typed_helpers i |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
138 |
| NONE => false) |
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
139 |
|
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
140 |
val leo2_ext = "extcnf_equal_neg" |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
141 |
val isa_ext = Thm.get_name_hint @{thm ext} |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
142 |
val isa_short_ext = Long_Name.base_name isa_ext |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
143 |
|
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
144 |
fun ext_name ctxt = |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
145 |
if Thm.eq_thm_prop (@{thm ext}, |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
146 |
singleton (Attrib.eval_thms ctxt) (Facts.named isa_short_ext, [])) then |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
147 |
isa_short_ext |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
148 |
else |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
149 |
isa_ext |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
150 |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
151 |
fun add_fact _ facts_offset fact_names (Inference (name, _, [])) = |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
152 |
union (op =) (resolve_fact facts_offset fact_names name) |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
153 |
| add_fact ctxt _ _ (Inference (_, _, deps)) = |
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
154 |
if AList.defined (op =) deps leo2_ext then |
43421 | 155 |
insert (op =) (ext_name ctxt, Extensionality) |
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
156 |
else |
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
157 |
I |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
158 |
| add_fact _ _ _ _ = I |
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
159 |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
160 |
fun used_facts_in_atp_proof ctxt facts_offset fact_names atp_proof = |
43296
755e3d5ea3f2
avoid duplicate facts, which confuse the minimizer output
blanchet
parents:
43291
diff
changeset
|
161 |
if null atp_proof then Vector.foldl (uncurry (union (op =))) [] fact_names |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
162 |
else fold (add_fact ctxt facts_offset fact_names) atp_proof [] |
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
163 |
|
43291
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
164 |
fun is_conjecture_used_in_proof conjecture_shape = |
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
165 |
exists (fn Inference (name, _, []) => is_conjecture conjecture_shape name |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
166 |
| _ => false) |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
167 |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
168 |
fun used_facts_in_unsound_atp_proof _ _ _ _ [] = NONE |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
169 |
| used_facts_in_unsound_atp_proof ctxt conjecture_shape facts_offset |
42876
e336ef6313aa
more informative message when Sledgehammer finds an unsound proof
blanchet
parents:
42761
diff
changeset
|
170 |
fact_names atp_proof = |
43291
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
171 |
let |
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
172 |
val used_facts = |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
173 |
used_facts_in_atp_proof ctxt facts_offset fact_names atp_proof |
43291
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
174 |
in |
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
175 |
if forall (is_locality_global o snd) used_facts andalso |
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
176 |
not (is_conjecture_used_in_proof conjecture_shape atp_proof) then |
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
177 |
SOME (map fst used_facts) |
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
178 |
else |
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
179 |
NONE |
9f33b4ec866c
don't generate unsound proof error for missing proofs
blanchet
parents:
43233
diff
changeset
|
180 |
end |
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
181 |
|
43033 | 182 |
fun uses_typed_helpers typed_helpers = |
183 |
exists (fn Inference (name, _, []) => is_typed_helper typed_helpers name |
|
184 |
| _ => false) |
|
185 |
||
186 |
||
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
187 |
(** Soft-core proof reconstruction: Metis one-liner **) |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
188 |
|
43228
2ed2f092e990
obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents:
43212
diff
changeset
|
189 |
(* unfortunate leaking abstraction *) |
43233
2749c357f865
use the proper prover name, e.g. metis_full_types, not metis (full_types), for minimizing
blanchet
parents:
43228
diff
changeset
|
190 |
fun name_of_reconstructor Metis = "metis" |
2749c357f865
use the proper prover name, e.g. metis_full_types, not metis (full_types), for minimizing
blanchet
parents:
43228
diff
changeset
|
191 |
| name_of_reconstructor Metis_Full_Types = "metis (full_types)" |
2749c357f865
use the proper prover name, e.g. metis_full_types, not metis (full_types), for minimizing
blanchet
parents:
43228
diff
changeset
|
192 |
| name_of_reconstructor Metis_No_Types = "metis (no_types)" |
2749c357f865
use the proper prover name, e.g. metis_full_types, not metis (full_types), for minimizing
blanchet
parents:
43228
diff
changeset
|
193 |
| name_of_reconstructor (SMT _) = "smt" |
43033 | 194 |
|
195 |
fun reconstructor_settings (SMT settings) = settings |
|
196 |
| reconstructor_settings _ = "" |
|
197 |
||
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
198 |
fun string_for_label (s, num) = s ^ string_of_int num |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
199 |
|
43033 | 200 |
fun show_time NONE = "" |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
43033
diff
changeset
|
201 |
| show_time (SOME ext_time) = " (" ^ string_from_ext_time ext_time ^ ")" |
43033 | 202 |
|
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
203 |
fun set_settings "" = "" |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
204 |
| set_settings settings = "using [[" ^ settings ^ "]] " |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
205 |
fun apply_on_subgoal settings _ 1 = set_settings settings ^ "by " |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
206 |
| apply_on_subgoal settings 1 _ = set_settings settings ^ "apply " |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
207 |
| apply_on_subgoal settings i n = |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
208 |
"prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal settings 1 n |
44002 | 209 |
fun command_call name [] = |
210 |
name |> not (Lexicon.is_identifier name) ? enclose "(" ")" |
|
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
211 |
| command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")" |
43033 | 212 |
fun try_command_line banner time command = |
213 |
banner ^ ": " ^ Markup.markup Markup.sendback command ^ show_time time ^ "." |
|
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
214 |
fun using_labels [] = "" |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
215 |
| using_labels ls = |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
216 |
"using " ^ space_implode " " (map string_for_label ls) ^ " " |
43033 | 217 |
fun reconstructor_command reconstructor i n (ls, ss) = |
218 |
using_labels ls ^ |
|
219 |
apply_on_subgoal (reconstructor_settings reconstructor) i n ^ |
|
43233
2749c357f865
use the proper prover name, e.g. metis_full_types, not metis (full_types), for minimizing
blanchet
parents:
43228
diff
changeset
|
220 |
command_call (name_of_reconstructor reconstructor) ss |
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
221 |
fun minimize_line _ [] = "" |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
222 |
| minimize_line minimize_command ss = |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
223 |
case minimize_command ss of |
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
224 |
"" => "" |
43006 | 225 |
| command => "\nTo minimize: " ^ Markup.markup Markup.sendback command ^ "." |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
226 |
|
40723
a82badd0e6ef
put facts found by SMT solver in alphabetical order and omit chained facts, as was done already for ATP proofs
blanchet
parents:
40627
diff
changeset
|
227 |
val split_used_facts = |
a82badd0e6ef
put facts found by SMT solver in alphabetical order and omit chained facts, as was done already for ATP proofs
blanchet
parents:
40627
diff
changeset
|
228 |
List.partition (curry (op =) Chained o snd) |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
229 |
#> 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
|
230 |
|
43033 | 231 |
fun one_line_proof_text (preplay, banner, used_facts, minimize_command, |
43037 | 232 |
subgoal, subgoal_count) = |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
233 |
let |
43033 | 234 |
val (chained, extra) = split_used_facts used_facts |
43166 | 235 |
val (failed, reconstructor, ext_time) = |
43033 | 236 |
case preplay of |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43039
diff
changeset
|
237 |
Played (reconstructor, time) => |
43166 | 238 |
(false, reconstructor, (SOME (false, time))) |
43033 | 239 |
| Trust_Playable (reconstructor, time) => |
43166 | 240 |
(false, reconstructor, |
43033 | 241 |
case time of |
242 |
NONE => NONE |
|
243 |
| SOME time => |
|
244 |
if time = Time.zeroTime then NONE else SOME (true, time)) |
|
43166 | 245 |
| Failed_to_Play reconstructor => (true, reconstructor, NONE) |
43033 | 246 |
val try_line = |
43166 | 247 |
([], map fst extra) |
248 |
|> reconstructor_command reconstructor subgoal subgoal_count |
|
249 |
|> (if failed then enclose "One-line proof reconstruction failed: " "." |
|
250 |
else try_command_line banner ext_time) |
|
43033 | 251 |
in try_line ^ minimize_line minimize_command (map fst (extra @ chained)) end |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
252 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
253 |
(** 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
|
254 |
|
39425 | 255 |
fun forall_of v t = HOLogic.all_const (fastype_of v) $ lambda v t |
256 |
fun exists_of v t = HOLogic.exists_const (fastype_of v) $ lambda v t |
|
257 |
||
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
258 |
fun make_tvar s = TVar (("'" ^ s, 0), HOLogic.typeS) |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
259 |
fun make_tfree ctxt w = |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
260 |
let val ww = "'" ^ w in |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
261 |
TFree (ww, the_default HOLogic.typeS (Variable.def_sort ctxt (ww, ~1))) |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
262 |
end |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
263 |
|
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
264 |
val indent_size = 2 |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
265 |
val no_label = ("", ~1) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
266 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
267 |
val raw_prefix = "X" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
268 |
val assum_prefix = "A" |
42180
a6c141925a8a
added monomorphization option to Sledgehammer ATPs -- this looks promising but is still off by default
blanchet
parents:
41742
diff
changeset
|
269 |
val have_prefix = "F" |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
270 |
|
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
271 |
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
|
272 |
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
|
273 |
[j] => (conjecture_prefix, j) |
39455 | 274 |
| _ => case Int.fromString (fst name) of |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
275 |
SOME j => (raw_prefix, j) |
39455 | 276 |
| NONE => (raw_prefix ^ fst name, 0) |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
277 |
|
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
278 |
(**** INTERPRETATION OF TSTP SYNTAX TREES ****) |
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
279 |
|
43678 | 280 |
exception HO_TERM of (string, string) ho_term list |
281 |
exception FORMULA of (string, string, (string, string) ho_term) formula list |
|
37991 | 282 |
exception SAME of unit |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
283 |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
284 |
(* Type variables are given the basic sort "HOL.type". Some will later be |
37991 | 285 |
constrained by information from type literals, or by type inference. *) |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
286 |
fun typ_from_atp ctxt (u as ATerm (a, us)) = |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
287 |
let val Ts = map (typ_from_atp ctxt) us in |
38748 | 288 |
case strip_prefix_and_unascii type_const_prefix a of |
37991 | 289 |
SOME b => Type (invert_const b, Ts) |
290 |
| NONE => |
|
291 |
if not (null us) then |
|
43678 | 292 |
raise HO_TERM [u] (* only "tconst"s have type arguments *) |
38748 | 293 |
else case strip_prefix_and_unascii tfree_prefix a of |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
294 |
SOME b => make_tfree ctxt b |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
295 |
| NONE => |
43302
566f970006e5
improve sort inference in Metis proofs -- in some rare cases Metis steals Isabelle's variable names and the sorts must then be inferred as well
blanchet
parents:
43296
diff
changeset
|
296 |
(* Could be an Isabelle variable or a variable from the ATP, say "X1" |
566f970006e5
improve sort inference in Metis proofs -- in some rare cases Metis steals Isabelle's variable names and the sorts must then be inferred as well
blanchet
parents:
43296
diff
changeset
|
297 |
or "_5018". Sometimes variables from the ATP are indistinguishable |
566f970006e5
improve sort inference in Metis proofs -- in some rare cases Metis steals Isabelle's variable names and the sorts must then be inferred as well
blanchet
parents:
43296
diff
changeset
|
298 |
from Isabelle variables, which forces us to use a type parameter in |
566f970006e5
improve sort inference in Metis proofs -- in some rare cases Metis steals Isabelle's variable names and the sorts must then be inferred as well
blanchet
parents:
43296
diff
changeset
|
299 |
all cases. *) |
566f970006e5
improve sort inference in Metis proofs -- in some rare cases Metis steals Isabelle's variable names and the sorts must then be inferred as well
blanchet
parents:
43296
diff
changeset
|
300 |
(a |> perhaps (strip_prefix_and_unascii tvar_prefix), HOLogic.typeS) |
566f970006e5
improve sort inference in Metis proofs -- in some rare cases Metis steals Isabelle's variable names and the sorts must then be inferred as well
blanchet
parents:
43296
diff
changeset
|
301 |
|> Type_Infer.param 0 |
37991 | 302 |
end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
303 |
|
38014 | 304 |
(* Type class literal applied to a type. Returns triple of polarity, class, |
305 |
type. *) |
|
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
306 |
fun type_constraint_from_term ctxt (u as ATerm (a, us)) = |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
307 |
case (strip_prefix_and_unascii class_prefix a, map (typ_from_atp ctxt) us) of |
42606
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
308 |
(SOME b, [T]) => (b, T) |
43678 | 309 |
| _ => raise HO_TERM [u] |
38014 | 310 |
|
43907
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
311 |
(* Accumulate type constraints in a formula: negative type literals. *) |
38014 | 312 |
fun add_var (key, z) = Vartab.map_default (key, []) (cons z) |
42606
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
313 |
fun add_type_constraint false (cl, TFree (a ,_)) = add_var ((a, ~1), cl) |
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
314 |
| add_type_constraint false (cl, TVar (ix, _)) = add_var (ix, cl) |
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
315 |
| add_type_constraint _ _ = I |
38014 | 316 |
|
43094 | 317 |
fun repair_variable_name f s = |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
318 |
let |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
319 |
fun subscript_name s n = s ^ nat_subscript n |
38488 | 320 |
val s = String.map f s |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
321 |
in |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
322 |
case space_explode "_" s of |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
323 |
[_] => (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
|
324 |
(cs1 as _ :: _, cs2 as _ :: _) => |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
325 |
subscript_name (String.implode cs1) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
326 |
(the (Int.fromString (String.implode cs2))) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
327 |
| (_, _) => s) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
328 |
| [s1, s2] => (case Int.fromString s2 of |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
329 |
SOME n => subscript_name s1 n |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
330 |
| NONE => s) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
331 |
| _ => s |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
332 |
end |
43182
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
333 |
|
43907
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
334 |
(* The number of type arguments of a constant, zero if it's monomorphic. For |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
335 |
(instances of) Skolem pseudoconstants, this information is encoded in the |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
336 |
constant name. *) |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
337 |
fun num_type_args thy s = |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
338 |
if String.isPrefix skolem_const_prefix s then |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
339 |
s |> space_explode Long_Name.separator |> List.last |> Int.fromString |> the |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
340 |
else |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
341 |
(s, Sign.the_const_type thy s) |> Sign.const_typargs thy |> length |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
342 |
|
43182
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
343 |
fun slack_fastype_of t = fastype_of t handle TERM _ => HOLogic.typeT |
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
344 |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
345 |
(* First-order translation. No types are known for variables. "HOLogic.typeT" |
38014 | 346 |
should allow them to be inferred. *) |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
347 |
fun term_from_atp ctxt textual sym_tab = |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
348 |
let |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
349 |
val thy = Proof_Context.theory_of ctxt |
43212 | 350 |
(* For Metis, we use 1 rather than 0 because variable references in clauses |
351 |
may otherwise conflict with variable constraints in the goal. At least, |
|
352 |
type inference often fails otherwise. See also "axiom_inference" in |
|
353 |
"Metis_Reconstruct". *) |
|
43094 | 354 |
val var_index = if textual then 0 else 1 |
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
355 |
fun do_term extra_ts opt_T u = |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
356 |
case u of |
42539
f6ba908b8b27
generate typing for "hBOOL" in "Many_Typed" mode + tuning
blanchet
parents:
42531
diff
changeset
|
357 |
ATerm (a, us) => |
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42943
diff
changeset
|
358 |
if String.isPrefix simple_type_prefix a then |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42943
diff
changeset
|
359 |
@{const True} (* ignore TPTP type information *) |
43000
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
360 |
else if a = tptp_equal then |
43093 | 361 |
let val ts = map (do_term [] NONE) us in |
43094 | 362 |
if textual andalso length ts = 2 andalso |
363 |
hd ts aconv List.last ts then |
|
39106 | 364 |
(* Vampire is keen on producing these. *) |
365 |
@{const True} |
|
366 |
else |
|
367 |
list_comb (Const (@{const_name HOL.eq}, HOLogic.typeT), ts) |
|
368 |
end |
|
43000
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
369 |
else case strip_prefix_and_unascii const_prefix a of |
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
370 |
SOME s => |
42761
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
371 |
let |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
372 |
val ((s', s), mangled_us) = s |> unmangled_const |>> `invert_const |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
373 |
in |
42755
4603154a3018
robustly detect how many type args were passed to the ATP, even if some of them were omitted
blanchet
parents:
42751
diff
changeset
|
374 |
if s' = type_tag_name then |
42589
9f7c48463645
restructured type systems some more -- the old naming schemes had "argshg diff |less" and "tagshg diff |less" as equivalent and didn't support a monomorphic version of "tags"
blanchet
parents:
42587
diff
changeset
|
375 |
case mangled_us @ us of |
9f7c48463645
restructured type systems some more -- the old naming schemes had "argshg diff |less" and "tagshg diff |less" as equivalent and didn't support a monomorphic version of "tags"
blanchet
parents:
42587
diff
changeset
|
376 |
[typ_u, term_u] => |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
377 |
do_term extra_ts (SOME (typ_from_atp ctxt typ_u)) term_u |
43678 | 378 |
| _ => raise HO_TERM us |
42966
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
blanchet
parents:
42962
diff
changeset
|
379 |
else if s' = predicator_name then |
43093 | 380 |
do_term [] (SOME @{typ bool}) (hd us) |
42966
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
blanchet
parents:
42962
diff
changeset
|
381 |
else if s' = app_op_name then |
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
382 |
let val extra_t = do_term [] NONE (List.last us) in |
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
383 |
do_term (extra_t :: extra_ts) |
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
384 |
(case opt_T of |
43182
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
385 |
SOME T => SOME (slack_fastype_of extra_t --> T) |
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
386 |
| NONE => NONE) |
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
387 |
(nth us (length us - 2)) |
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
388 |
end |
44396
66b9b3fcd608
started cleaning up polymorphic monotonicity-based encodings, based on discussions with Nick Smallbone
blanchet
parents:
44121
diff
changeset
|
389 |
else if s' = type_guard_name then |
42551
cd99d6d3027a
reconstruct TFF type predicates correctly for ToFoF
blanchet
parents:
42549
diff
changeset
|
390 |
@{const True} (* ignore type predicates *) |
42549
b9754f26c7bc
handle special constants correctly in Isar proof reconstruction code, especially type predicates
blanchet
parents:
42544
diff
changeset
|
391 |
else |
b9754f26c7bc
handle special constants correctly in Isar proof reconstruction code, especially type predicates
blanchet
parents:
42544
diff
changeset
|
392 |
let |
43191
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
393 |
val new_skolem = String.isPrefix new_skolem_const_prefix s |
42755
4603154a3018
robustly detect how many type args were passed to the ATP, even if some of them were omitted
blanchet
parents:
42751
diff
changeset
|
394 |
val num_ty_args = |
4603154a3018
robustly detect how many type args were passed to the ATP, even if some of them were omitted
blanchet
parents:
42751
diff
changeset
|
395 |
length us - the_default 0 (Symtab.lookup sym_tab s) |
42549
b9754f26c7bc
handle special constants correctly in Isar proof reconstruction code, especially type predicates
blanchet
parents:
42544
diff
changeset
|
396 |
val (type_us, term_us) = |
b9754f26c7bc
handle special constants correctly in Isar proof reconstruction code, especially type predicates
blanchet
parents:
42544
diff
changeset
|
397 |
chop num_ty_args us |>> append mangled_us |
43093 | 398 |
val term_ts = map (do_term [] NONE) term_us |
42549
b9754f26c7bc
handle special constants correctly in Isar proof reconstruction code, especially type predicates
blanchet
parents:
42544
diff
changeset
|
399 |
val T = |
43183
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
400 |
(if not (null type_us) andalso |
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
401 |
num_type_args thy s' = length type_us then |
43191
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
402 |
let val Ts = type_us |> map (typ_from_atp ctxt) in |
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
403 |
if new_skolem then |
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
404 |
SOME (Type_Infer.paramify_vars (tl Ts ---> hd Ts)) |
43200
ca7b0a48515d
imported patch metis_reconstr_give_type_infer_a_chance
blanchet
parents:
43199
diff
changeset
|
405 |
else if textual then |
ca7b0a48515d
imported patch metis_reconstr_give_type_infer_a_chance
blanchet
parents:
43199
diff
changeset
|
406 |
try (Sign.const_instance thy) (s', Ts) |
43191
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
407 |
else |
43200
ca7b0a48515d
imported patch metis_reconstr_give_type_infer_a_chance
blanchet
parents:
43199
diff
changeset
|
408 |
NONE |
43191
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
409 |
end |
43183
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
410 |
else |
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
411 |
NONE) |
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
412 |
|> (fn SOME T => T |
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
413 |
| NONE => map slack_fastype_of term_ts ---> |
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
414 |
(case opt_T of |
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
415 |
SOME T => T |
faece9668bce
don't throw exception on unknown constants (e.g. skolems), and give more precise type to applied functions
blanchet
parents:
43182
diff
changeset
|
416 |
| NONE => HOLogic.typeT)) |
43191
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
417 |
val t = |
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
418 |
if new_skolem then |
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
419 |
Var ((new_skolem_var_name_from_const s, var_index), T) |
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
420 |
else |
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
421 |
Const (unproxify_const s', T) |
0a72c0527111
fixed reconstruction of new Skolem constants in new Metis
blanchet
parents:
43184
diff
changeset
|
422 |
in list_comb (t, term_ts @ extra_ts) end |
42549
b9754f26c7bc
handle special constants correctly in Isar proof reconstruction code, especially type predicates
blanchet
parents:
42544
diff
changeset
|
423 |
end |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
424 |
| NONE => (* a free or schematic variable *) |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
425 |
let |
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
426 |
val ts = map (do_term [] NONE) us @ extra_ts |
43182
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
427 |
val T = map slack_fastype_of ts ---> HOLogic.typeT |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
428 |
val t = |
38748 | 429 |
case strip_prefix_and_unascii fixed_var_prefix a of |
43907
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
430 |
SOME b => |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
431 |
(* FIXME: reconstruction of lambda-lifting *) |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
432 |
Free (b, T) |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
433 |
| NONE => |
38748 | 434 |
case strip_prefix_and_unascii schematic_var_prefix a of |
43094 | 435 |
SOME b => Var ((b, var_index), T) |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
436 |
| NONE => |
43095 | 437 |
Var ((a |> textual ? repair_variable_name Char.toLower, |
438 |
var_index), T) |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
439 |
in list_comb (t, ts) end |
43093 | 440 |
in do_term [] end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
441 |
|
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
442 |
fun term_from_atom ctxt textual sym_tab pos (u as ATerm (s, _)) = |
38014 | 443 |
if String.isPrefix class_prefix s then |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
444 |
add_type_constraint pos (type_constraint_from_term ctxt u) |
38014 | 445 |
#> pair @{const True} |
446 |
else |
|
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
447 |
pair (term_from_atp ctxt textual sym_tab (SOME @{typ bool}) u) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
448 |
|
36555
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
449 |
val combinator_table = |
39953
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39710
diff
changeset
|
450 |
[(@{const_name Meson.COMBI}, @{thm Meson.COMBI_def_raw}), |
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39710
diff
changeset
|
451 |
(@{const_name Meson.COMBK}, @{thm Meson.COMBK_def_raw}), |
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39710
diff
changeset
|
452 |
(@{const_name Meson.COMBB}, @{thm Meson.COMBB_def_raw}), |
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39710
diff
changeset
|
453 |
(@{const_name Meson.COMBC}, @{thm Meson.COMBC_def_raw}), |
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39710
diff
changeset
|
454 |
(@{const_name Meson.COMBS}, @{thm Meson.COMBS_def_raw})] |
36555
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
455 |
|
42761
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
456 |
fun uncombine_term thy = |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
457 |
let |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
458 |
fun aux (t1 $ t2) = betapply (pairself aux (t1, t2)) |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
459 |
| aux (Abs (s, T, t')) = Abs (s, T, aux t') |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
460 |
| aux (t as Const (x as (s, _))) = |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
461 |
(case AList.lookup (op =) combinator_table s of |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
462 |
SOME thm => thm |> prop_of |> specialize_type thy x |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
463 |
|> Logic.dest_equals |> snd |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
464 |
| NONE => t) |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
465 |
| aux t = t |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
466 |
in aux end |
36555
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
467 |
|
37991 | 468 |
(* Update schematic type variables with detected sort constraints. It's not |
42563 | 469 |
totally clear whether this code is necessary. *) |
38014 | 470 |
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
|
471 |
let |
37991 | 472 |
fun do_type (Type (a, Ts)) = Type (a, map do_type Ts) |
473 |
| do_type (TVar (xi, s)) = |
|
474 |
TVar (xi, the_default s (Vartab.lookup tvar_tab xi)) |
|
475 |
| do_type (TFree z) = TFree z |
|
476 |
fun do_term (Const (a, T)) = Const (a, do_type T) |
|
477 |
| do_term (Free (a, T)) = Free (a, do_type T) |
|
478 |
| do_term (Var (xi, T)) = Var (xi, do_type T) |
|
479 |
| do_term (t as Bound _) = t |
|
480 |
| do_term (Abs (a, T, t)) = Abs (a, do_type T, do_term t) |
|
481 |
| do_term (t1 $ t2) = do_term t1 $ do_term t2 |
|
482 |
in t |> not (Vartab.is_empty tvar_tab) ? do_term end |
|
483 |
||
39425 | 484 |
fun quantify_over_var quant_of var_s t = |
485 |
let |
|
486 |
val vars = [] |> Term.add_vars t |> filter (fn ((s, _), _) => s = var_s) |
|
487 |
|> map Var |
|
488 |
in fold_rev quant_of vars t end |
|
37991 | 489 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
490 |
(* 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
|
491 |
appear in the formula. *) |
43184 | 492 |
fun prop_from_atp ctxt textual sym_tab phi = |
38014 | 493 |
let |
494 |
fun do_formula pos phi = |
|
37991 | 495 |
case phi of |
38014 | 496 |
AQuant (_, [], phi) => do_formula pos phi |
42526 | 497 |
| AQuant (q, (s, _) :: xs, phi') => |
38014 | 498 |
do_formula pos (AQuant (q, xs, phi')) |
42526 | 499 |
(* FIXME: TFF *) |
39425 | 500 |
#>> quantify_over_var (case q of |
501 |
AForall => forall_of |
|
502 |
| AExists => exists_of) |
|
43095 | 503 |
(s |> textual ? repair_variable_name Char.toLower) |
38014 | 504 |
| AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not |
37991 | 505 |
| AConn (c, [phi1, phi2]) => |
38014 | 506 |
do_formula (pos |> c = AImplies ? not) phi1 |
507 |
##>> do_formula pos phi2 |
|
508 |
#>> (case c of |
|
509 |
AAnd => s_conj |
|
510 |
| AOr => s_disj |
|
511 |
| AImplies => s_imp |
|
38038 | 512 |
| AIff => s_iff |
43163 | 513 |
| ANot => raise Fail "impossible connective") |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
514 |
| AAtom tm => term_from_atom ctxt textual sym_tab pos tm |
37991 | 515 |
| _ => raise FORMULA [phi] |
38014 | 516 |
in repair_tvar_sorts (do_formula true phi Vartab.empty) end |
37991 | 517 |
|
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
518 |
fun infer_formula_types ctxt = |
39288 | 519 |
Type.constraint HOLogic.boolT |
42761
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
520 |
#> Syntax.check_term |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
521 |
(Proof_Context.set_mode Proof_Context.mode_schematic ctxt) |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
522 |
|
43184 | 523 |
fun uncombined_etc_prop_from_atp ctxt textual sym_tab = |
43136
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
524 |
let val thy = Proof_Context.theory_of ctxt in |
43184 | 525 |
prop_from_atp ctxt textual sym_tab |
43176
29a3a1a7794d
only uncombine combinators in textual Isar proofs, not in Metis
blanchet
parents:
43168
diff
changeset
|
526 |
#> textual ? uncombine_term thy #> infer_formula_types ctxt |
43136
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
527 |
end |
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
528 |
|
43093 | 529 |
(**** Translation of TSTP files to Isar proofs ****) |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
530 |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
531 |
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
|
532 |
| 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
|
533 |
|
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
534 |
fun decode_line sym_tab (Definition (name, phi1, phi2)) ctxt = |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
535 |
let |
42361 | 536 |
val thy = Proof_Context.theory_of ctxt |
43184 | 537 |
val t1 = prop_from_atp ctxt true sym_tab phi1 |
36551 | 538 |
val vars = snd (strip_comb t1) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
539 |
val frees = map unvarify_term vars |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
540 |
val unvarify_args = subst_atomic (vars ~~ frees) |
43184 | 541 |
val t2 = prop_from_atp ctxt true sym_tab phi2 |
36551 | 542 |
val (t1, t2) = |
543 |
HOLogic.eq_const HOLogic.typeT $ t1 $ t2 |
|
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
544 |
|> unvarify_args |> uncombine_term thy |> infer_formula_types ctxt |
36555
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
545 |
|> HOLogic.dest_eq |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
546 |
in |
39368 | 547 |
(Definition (name, t1, t2), |
44121 | 548 |
fold Variable.declare_term (maps Misc_Legacy.term_frees [t1, t2]) ctxt) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
549 |
end |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
550 |
| decode_line sym_tab (Inference (name, u, deps)) ctxt = |
43184 | 551 |
let val t = u |> uncombined_etc_prop_from_atp ctxt true sym_tab in |
39368 | 552 |
(Inference (name, t, deps), |
44121 | 553 |
fold Variable.declare_term (Misc_Legacy.term_frees t) ctxt) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
554 |
end |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
555 |
fun decode_lines ctxt sym_tab lines = |
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
556 |
fst (fold_map (decode_line sym_tab) lines ctxt) |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
557 |
|
38035 | 558 |
fun is_same_inference _ (Definition _) = false |
559 |
| 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
|
560 |
|
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
561 |
(* 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
|
562 |
clsarity). *) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
563 |
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
|
564 |
|
39373 | 565 |
fun replace_one_dependency (old, new) dep = |
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
566 |
if is_same_atp_step dep old then new else [dep] |
39373 | 567 |
fun replace_dependencies_in_line _ (line as Definition _) = line |
568 |
| replace_dependencies_in_line p (Inference (name, t, deps)) = |
|
569 |
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
|
570 |
|
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40114
diff
changeset
|
571 |
(* Discard facts; consolidate adjacent lines that prove the same formula, since |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
572 |
they differ only in type information.*) |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
573 |
fun add_line _ _ (line as Definition _) lines = line :: lines |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
574 |
| add_line conjecture_shape fact_names (Inference (name, t, [])) lines = |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40114
diff
changeset
|
575 |
(* No dependencies: fact, conjecture, or (for Vampire) internal facts or |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
576 |
definitions. *) |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
577 |
if is_fact fact_names name then |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40114
diff
changeset
|
578 |
(* Facts are not proof lines. *) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
579 |
if is_only_type_information t then |
39373 | 580 |
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
|
581 |
(* Is there a repetition? If so, replace later line by earlier one. *) |
38035 | 582 |
else case take_prefix (not o is_same_inference t) lines of |
39373 | 583 |
(_, []) => lines (* no repetition of proof line *) |
39368 | 584 |
| (pre, Inference (name', _, _) :: post) => |
39373 | 585 |
pre @ map (replace_dependencies_in_line (name', [name])) post |
40069 | 586 |
| _ => raise Fail "unexpected inference" |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
587 |
else if is_conjecture conjecture_shape name then |
42606
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
588 |
Inference (name, s_not t, []) :: lines |
36551 | 589 |
else |
39373 | 590 |
map (replace_dependencies_in_line (name, [])) lines |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
591 |
| 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
|
592 |
(* 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
|
593 |
if is_only_type_information t then |
39368 | 594 |
Inference (name, t, deps) :: lines |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
595 |
(* Is there a repetition? If so, replace later line by earlier one. *) |
38035 | 596 |
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
|
597 |
(* FIXME: Doesn't this code risk conflating proofs involving different |
38035 | 598 |
types? *) |
39368 | 599 |
(_, []) => Inference (name, t, deps) :: lines |
600 |
| (pre, Inference (name', t', _) :: post) => |
|
601 |
Inference (name, t', deps) :: |
|
39373 | 602 |
pre @ map (replace_dependencies_in_line (name', [name])) post |
40069 | 603 |
| _ => raise Fail "unexpected inference" |
22044
6c0702a96076
More compact proof reconstruction: lines having fewer than !min_deps dependences are folded
paulson
parents:
22012
diff
changeset
|
604 |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
605 |
(* Recursively delete empty lines (type information) from the proof. *) |
39368 | 606 |
fun add_nontrivial_line (Inference (name, t, [])) lines = |
39373 | 607 |
if is_only_type_information t then delete_dependency name lines |
39368 | 608 |
else Inference (name, t, []) :: lines |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
609 |
| add_nontrivial_line line lines = line :: lines |
39373 | 610 |
and delete_dependency name lines = |
611 |
fold_rev add_nontrivial_line |
|
612 |
(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
|
613 |
|
37323 | 614 |
(* ATPs sometimes reuse free variable names in the strangest ways. Removing |
615 |
offending lines often does the trick. *) |
|
36560
45c1870f234f
fixed definition of "bad frees" so that it actually works
blanchet
parents:
36559
diff
changeset
|
616 |
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
|
617 |
| is_bad_free _ _ = false |
22470
0d52e5157124
No label on "show"; tries to remove dependencies more cleanly
paulson
parents:
22428
diff
changeset
|
618 |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
619 |
fun add_desired_line _ _ _ _ (line as Definition (name, _, _)) (j, lines) = |
39373 | 620 |
(j, line :: map (replace_dependencies_in_line (name, [])) lines) |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
621 |
| add_desired_line isar_shrink_factor conjecture_shape fact_names frees |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
622 |
(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
|
623 |
(j + 1, |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
624 |
if is_fact fact_names name orelse is_conjecture conjecture_shape name orelse |
39373 | 625 |
(* the last line must be kept *) |
626 |
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
|
627 |
(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
|
628 |
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
|
629 |
not (exists_subterm (is_bad_free frees) t) andalso |
39373 | 630 |
length deps >= 2 andalso j mod isar_shrink_factor = 0 andalso |
631 |
(* kill next to last line, which usually results in a trivial step *) |
|
632 |
j <> 1) then |
|
39368 | 633 |
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
|
634 |
else |
39373 | 635 |
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
|
636 |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
637 |
(** Isar proof construction and manipulation **) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
638 |
|
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
639 |
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
|
640 |
(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
|
641 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
642 |
type label = string * int |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
643 |
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
|
644 |
|
39452 | 645 |
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
|
646 |
|
39452 | 647 |
datatype isar_step = |
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
648 |
Fix of (string * typ) list | |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
649 |
Let of term * term | |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
650 |
Assume of label * term | |
39452 | 651 |
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
|
652 |
and byline = |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
653 |
ByMetis of facts | |
39452 | 654 |
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
|
655 |
|
36574 | 656 |
fun smart_case_split [] facts = ByMetis facts |
657 |
| smart_case_split proofs facts = CaseSplit (proofs, facts) |
|
658 |
||
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
659 |
fun add_fact_from_dependency conjecture_shape facts_offset fact_names name = |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
660 |
if is_fact fact_names name then |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
661 |
apsnd (union (op =) (map fst (resolve_fact facts_offset fact_names name))) |
36475
05209b869a6b
new Isar proof construction code: stringfy axiom names correctly
blanchet
parents:
36474
diff
changeset
|
662 |
else |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
663 |
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
|
664 |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
665 |
fun step_for_line _ _ _ _ (Definition (_, t1, t2)) = Let (t1, t2) |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
666 |
| step_for_line conjecture_shape _ _ _ (Inference (name, t, [])) = |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
667 |
Assume (raw_label_for_name conjecture_shape name, t) |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
668 |
| step_for_line conjecture_shape facts_offset fact_names j |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
669 |
(Inference (name, t, deps)) = |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
670 |
Have (if j = 1 then [Show] else [], |
39425 | 671 |
raw_label_for_name conjecture_shape name, |
672 |
fold_rev forall_of (map Var (Term.add_vars t [])) t, |
|
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
673 |
ByMetis (fold (add_fact_from_dependency conjecture_shape facts_offset |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
674 |
fact_names) |
39373 | 675 |
deps ([], []))) |
36291
b4c2043cc96c
added Isar proof reconstruction support for SPASS -- which means all provers can now yield Isar proofs;
blanchet
parents:
36288
diff
changeset
|
676 |
|
39454 | 677 |
fun repair_name "$true" = "c_True" |
678 |
| repair_name "$false" = "c_False" |
|
43000
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
679 |
| repair_name "$$e" = tptp_equal (* seen in Vampire proofs *) |
39454 | 680 |
| repair_name s = |
43000
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
681 |
if is_tptp_equal s orelse |
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
682 |
(* seen in Vampire proofs *) |
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
683 |
(String.isPrefix "sQ" s andalso String.isSuffix "_eqProxy" s) then |
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
blanchet
parents:
42998
diff
changeset
|
684 |
tptp_equal |
39454 | 685 |
else |
686 |
s |
|
687 |
||
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
688 |
fun isar_proof_from_atp_proof pool ctxt isar_shrink_factor conjecture_shape |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
689 |
facts_offset fact_names sym_tab params frees atp_proof = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
690 |
let |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
691 |
val lines = |
42449
494e4ac5b0f8
detect some unsound proofs before showing them to the user
blanchet
parents:
42361
diff
changeset
|
692 |
atp_proof |
42968
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
blanchet
parents:
42966
diff
changeset
|
693 |
|> clean_up_atp_proof_dependencies |
39454 | 694 |
|> nasty_atp_proof pool |
695 |
|> map_term_names_in_atp_proof repair_name |
|
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
696 |
|> decode_lines ctxt sym_tab |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
697 |
|> rpair [] |-> fold_rev (add_line conjecture_shape fact_names) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
698 |
|> rpair [] |-> fold_rev add_nontrivial_line |
42647
59142dbfa3ba
no need to generate fact numbers for polymorphic type systems -- this confuses the TPTP exporter
blanchet
parents:
42613
diff
changeset
|
699 |
|> rpair (0, []) |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
700 |
|-> fold_rev (add_desired_line isar_shrink_factor conjecture_shape |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
701 |
fact_names frees) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
702 |
|> snd |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
703 |
in |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
704 |
(if null params then [] else [Fix params]) @ |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
705 |
map2 (step_for_line conjecture_shape facts_offset fact_names) |
42541
8938507b2054
move type declarations to the front, for TFF-compliance
blanchet
parents:
42539
diff
changeset
|
706 |
(length lines downto 1) lines |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
707 |
end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
708 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
709 |
(* 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
|
710 |
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
|
711 |
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
|
712 |
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
|
713 |
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
|
714 |
case split. *) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
715 |
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
|
716 |
|
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
|
717 |
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
|
718 |
(case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
719 |
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
|
720 |
| 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
|
721 |
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
|
722 |
| 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
|
723 |
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
|
724 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
725 |
fun new_labels_of_step (Fix _) = [] |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
726 |
| 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
|
727 |
| 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
|
728 |
| 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
|
729 |
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
|
730 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
731 |
val join_proofs = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
732 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
733 |
fun aux _ [] = NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
734 |
| 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
|
735 |
if exists null proofs then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
736 |
NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
737 |
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
|
738 |
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
|
739 |
else case hd proof1 of |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
740 |
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
|
741 |
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
|
742 |
| _ => false) (tl proofs) andalso |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
743 |
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
|
744 |
(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
|
745 |
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
|
746 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
747 |
NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
748 |
| _ => NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
749 |
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
|
750 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
751 |
fun case_split_qualifiers proofs = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
752 |
case length proofs of |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
753 |
0 => [] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
754 |
| 1 => [Then] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
755 |
| _ => [Ultimately] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
756 |
|
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
757 |
fun redirect_proof hyp_ts concl_t proof = |
33310 | 758 |
let |
37324
d77250dd2416
fix bugs in Sledgehammer's Isar proof "redirection" code
blanchet
parents:
37323
diff
changeset
|
759 |
(* 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
|
760 |
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
|
761 |
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
|
762 |
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
|
763 |
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
|
764 |
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
|
765 |
| 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
|
766 |
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
|
767 |
| 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
|
768 |
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
|
769 |
| 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
|
770 |
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
|
771 |
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
|
772 |
| 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
|
773 |
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
|
774 |
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
|
775 |
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
|
776 |
else |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
777 |
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
|
778 |
end |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
779 |
| 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
|
780 |
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
|
781 |
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
|
782 |
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
|
783 |
fun backpatch_labels patches ls = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
784 |
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
|
785 |
fun second_pass end_qs ([], assums, patches) = |
37324
d77250dd2416
fix bugs in Sledgehammer's Isar proof "redirection" code
blanchet
parents:
37323
diff
changeset
|
786 |
([Have (end_qs, no_label, concl_t, |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
787 |
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
|
788 |
| 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
|
789 |
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
|
790 |
| 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
|
791 |
patches) = |
39373 | 792 |
(if member (op =) (snd (snd patches)) l andalso |
793 |
not (member (op =) (fst (snd patches)) l) andalso |
|
794 |
not (AList.defined (op =) (fst patches) l) then |
|
795 |
second_pass end_qs (proof, assums, patches ||> apsnd (append ls)) |
|
796 |
else case List.partition (member (op =) contra_ls) ls of |
|
797 |
([contra_l], co_ls) => |
|
798 |
if member (op =) qs Show then |
|
799 |
second_pass end_qs (proof, assums, |
|
800 |
patches |>> cons (contra_l, (co_ls, ss))) |
|
801 |
else |
|
802 |
second_pass end_qs |
|
803 |
(proof, assums, |
|
804 |
patches |>> cons (contra_l, (l :: co_ls, ss))) |
|
805 |
|>> cons (if member (op =) (fst (snd patches)) l then |
|
42606
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
806 |
Assume (l, s_not t) |
39373 | 807 |
else |
42606
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
808 |
Have (qs, l, s_not t, |
39373 | 809 |
ByMetis (backpatch_label patches l))) |
810 |
| (contra_ls as _ :: _, co_ls) => |
|
811 |
let |
|
812 |
val proofs = |
|
813 |
map_filter |
|
814 |
(fn l => |
|
815 |
if l = concl_l then |
|
816 |
NONE |
|
817 |
else |
|
818 |
let |
|
819 |
val drop_ls = filter (curry (op <>) l) contra_ls |
|
820 |
in |
|
821 |
second_pass [] |
|
822 |
(proof, assums, |
|
823 |
patches ||> apfst (insert (op =) l) |
|
824 |
||> apsnd (union (op =) drop_ls)) |
|
825 |
|> fst |> SOME |
|
826 |
end) contra_ls |
|
827 |
val (assumes, facts) = |
|
828 |
if member (op =) (fst (snd patches)) l then |
|
42606
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
829 |
([Assume (l, s_not t)], (l :: co_ls, ss)) |
39373 | 830 |
else |
831 |
([], (co_ls, ss)) |
|
832 |
in |
|
833 |
(case join_proofs proofs of |
|
834 |
SOME (l, t, proofs, proof_tail) => |
|
835 |
Have (case_split_qualifiers proofs @ |
|
836 |
(if null proof_tail then end_qs else []), l, t, |
|
837 |
smart_case_split proofs facts) :: proof_tail |
|
838 |
| NONE => |
|
839 |
[Have (case_split_qualifiers proofs @ end_qs, no_label, |
|
840 |
concl_t, smart_case_split proofs facts)], |
|
841 |
patches) |
|
842 |
|>> append assumes |
|
843 |
end |
|
844 |
| _ => raise Fail "malformed proof") |
|
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
845 |
| second_pass _ _ = raise Fail "malformed proof" |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
846 |
val proof_bottom = |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
847 |
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
|
848 |
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
|
849 |
|
38490 | 850 |
(* 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
|
851 |
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
|
852 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
853 |
fun relabel_facts subst = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
854 |
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
|
855 |
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
|
856 |
(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
|
857 |
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
|
858 |
| 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
|
859 |
| 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
|
860 |
(Have (qs, l, t, |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
861 |
case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
862 |
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
|
863 |
| CaseSplit (proofs, facts) => |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
864 |
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
|
865 |
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
|
866 |
| 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
|
867 |
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
|
868 |
in do_proof end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
869 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
870 |
val then_chain_proof = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
871 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
872 |
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
|
873 |
| 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
|
874 |
| 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
|
875 |
(case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
876 |
ByMetis (ls, ss) => |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
877 |
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
|
878 |
(Then :: qs, l, t, |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
879 |
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
|
880 |
else |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
881 |
(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
|
882 |
| CaseSplit (proofs, facts) => |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
883 |
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
|
884 |
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
|
885 |
| 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
|
886 |
in aux no_label end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
887 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
888 |
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
|
889 |
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
|
890 |
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
|
891 |
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
|
892 |
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
|
893 |
| 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
|
894 |
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
|
895 |
case by of |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
896 |
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
|
897 |
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
|
898 |
| _ => 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
|
899 |
| 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
|
900 |
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
|
901 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
902 |
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
|
903 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
904 |
val relabel_proof = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
905 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
906 |
fun aux _ _ _ [] = [] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
907 |
| 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
|
908 |
if l = no_label then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
909 |
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
|
910 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
911 |
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
|
912 |
Assume (l', t) :: |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
913 |
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
|
914 |
end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
915 |
| 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
|
916 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
917 |
val (l', subst, next_fact) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
918 |
if l = no_label then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
919 |
(l, subst, next_fact) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
920 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
921 |
let |
42180
a6c141925a8a
added monomorphization option to Sledgehammer ATPs -- this looks promising but is still off by default
blanchet
parents:
41742
diff
changeset
|
922 |
val l' = (prefix_for_depth depth have_prefix, next_fact) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
923 |
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
|
924 |
val relabel_facts = |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
925 |
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
|
926 |
val by = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
927 |
case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
928 |
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
|
929 |
| CaseSplit (proofs, facts) => |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
930 |
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
|
931 |
relabel_facts facts) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
932 |
in |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
933 |
Have (qs, l', t, by) :: |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
934 |
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
|
935 |
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
|
936 |
| 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
|
937 |
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
|
938 |
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
|
939 |
|
42881
dbdfe2d5b6ab
automatically use "metisFT" when typed helpers are necessary
blanchet
parents:
42876
diff
changeset
|
940 |
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
|
941 |
let |
42761
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
942 |
val ctxt = |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
943 |
ctxt0 |> Config.put show_free_types false |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
944 |
|> Config.put show_types true |
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42759
diff
changeset
|
945 |
|> Config.put show_sorts true |
37319
42268dc7d6c4
show types in Isar proofs, but not for free variables;
blanchet
parents:
37172
diff
changeset
|
946 |
fun fix_print_mode f x = |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39115
diff
changeset
|
947 |
Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN) |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39115
diff
changeset
|
948 |
(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
|
949 |
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
|
950 |
fun do_free (s, T) = |
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
951 |
maybe_quote s ^ " :: " ^ |
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
952 |
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
|
953 |
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
|
954 |
fun do_have qs = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
955 |
(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
|
956 |
(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
|
957 |
(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
|
958 |
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
|
959 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
960 |
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
|
961 |
val do_term = maybe_quote o fix_print_mode (Syntax.string_of_term ctxt) |
43228
2ed2f092e990
obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents:
43212
diff
changeset
|
962 |
val reconstructor = if full_types then Metis_Full_Types else Metis |
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
|
963 |
fun do_facts (ls, ss) = |
43033 | 964 |
reconstructor_command reconstructor 1 1 |
965 |
(ls |> sort_distinct (prod_ord string_ord int_ord), |
|
966 |
ss |> sort_distinct string_ord) |
|
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
967 |
and do_step ind (Fix xs) = |
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
968 |
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
|
969 |
| do_step ind (Let (t1, t2)) = |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
970 |
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
|
971 |
| 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
|
972 |
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
|
973 |
| 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
|
974 |
do_indent ind ^ do_have qs ^ " " ^ |
36479 | 975 |
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
|
976 |
| 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
|
977 |
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
|
978 |
(map (do_block ind) proofs) ^ |
36479 | 979 |
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
|
980 |
do_facts facts ^ "\n" |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
981 |
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
|
982 |
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
|
983 |
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
|
984 |
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
|
985 |
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
|
986 |
suffix ^ "\n" |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
987 |
end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
988 |
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
|
989 |
(* 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
|
990 |
directly. *) |
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
991 |
and do_proof [Have (_, _, _, ByMetis _)] = "" |
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
992 |
| 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
|
993 |
(if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^ |
39452 | 994 |
do_indent 0 ^ "proof -\n" ^ do_steps "" "" 1 proof ^ do_indent 0 ^ |
995 |
(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
|
996 |
in do_proof end |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
997 |
|
43062
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
998 |
fun isar_proof_text ctxt isar_proof_requested |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
999 |
(debug, full_types, isar_shrink_factor, pool, conjecture_shape, |
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
1000 |
facts_offset, fact_names, sym_tab, atp_proof, goal) |
43037 | 1001 |
(one_line_params as (_, _, _, _, subgoal, subgoal_count)) = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
1002 |
let |
43062
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1003 |
val isar_shrink_factor = |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1004 |
(if isar_proof_requested then 1 else 2) * isar_shrink_factor |
43037 | 1005 |
val (params, hyp_ts, concl_t) = strip_subgoal ctxt goal subgoal |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
1006 |
val frees = fold Term.add_frees (concl_t :: hyp_ts) [] |
43033 | 1007 |
val one_line_proof = one_line_proof_text one_line_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
|
1008 |
fun isar_proof_for () = |
43033 | 1009 |
case atp_proof |
43304
6901ebafbb8d
cleaner fact freshening, which also works in corner cases, e.g. if two backquoted facts have the same name (but have different variable indices)
blanchet
parents:
43302
diff
changeset
|
1010 |
|> isar_proof_from_atp_proof pool ctxt isar_shrink_factor |
43135
8c32a0160b0d
more uniform handling of tfree sort inference in ATP reconstruction code, based on what Metis always has done
blanchet
parents:
43131
diff
changeset
|
1011 |
conjecture_shape facts_offset fact_names sym_tab params frees |
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
1012 |
|> 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
|
1013 |
|> kill_duplicate_assumptions_in_proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
1014 |
|> then_chain_proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
1015 |
|> kill_useless_labels_in_proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
1016 |
|> relabel_proof |
43037 | 1017 |
|> string_for_proof ctxt full_types subgoal subgoal_count of |
43062
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1018 |
"" => |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1019 |
if isar_proof_requested then |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1020 |
"\nNo structured proof available (proof too short)." |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1021 |
else |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1022 |
"" |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1023 |
| proof => |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1024 |
"\n\n" ^ (if isar_proof_requested then "Structured proof" |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1025 |
else "Perhaps this will work") ^ |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1026 |
":\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
|
1027 |
val isar_proof = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
1028 |
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
|
1029 |
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
|
1030 |
else |
43062
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1031 |
case try isar_proof_for () of |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1032 |
SOME s => s |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1033 |
| NONE => if isar_proof_requested then |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1034 |
"\nWarning: The Isar proof construction failed." |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1035 |
else |
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1036 |
"" |
43033 | 1037 |
in one_line_proof ^ isar_proof end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
1038 |
|
43033 | 1039 |
fun proof_text ctxt isar_proof isar_params |
1040 |
(one_line_params as (preplay, _, _, _, _, _)) = |
|
43166 | 1041 |
(if case preplay of Failed_to_Play _ => true | _ => isar_proof then |
43062
2834548a7a48
nicer failure message when one-line proof reconstruction fails
blanchet
parents:
43051
diff
changeset
|
1042 |
isar_proof_text ctxt isar_proof isar_params |
43033 | 1043 |
else |
1044 |
one_line_proof_text) one_line_params |
|
36223
217ca1273786
make Sledgehammer's minimizer also minimize Isar proofs
blanchet
parents:
36140
diff
changeset
|
1045 |
|
31038 | 1046 |
end; |