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