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