author | blanchet |
Fri, 01 Aug 2014 20:44:29 +0200 | |
changeset 57765 | f1108245ba11 |
parent 57717 | 949838aba487 |
child 57767 | 5bc204ca27ce |
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 |
|
49914 | 6 |
Basic 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 |
54811 | 11 |
type 'a atp_type = 'a ATP_Problem.atp_type |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
52758
diff
changeset
|
12 |
type ('a, 'b) atp_term = ('a, 'b) ATP_Problem.atp_term |
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
52758
diff
changeset
|
13 |
type ('a, 'b, 'c, 'd) atp_formula = ('a, 'b, 'c, 'd) ATP_Problem.atp_formula |
54500 | 14 |
type stature = ATP_Problem_Generate.stature |
54772 | 15 |
type atp_step_name = ATP_Proof.atp_step_name |
54499 | 16 |
type ('a, 'b) atp_step = ('a, 'b) ATP_Proof.atp_step |
17 |
type 'a atp_proof = 'a ATP_Proof.atp_proof |
|
45519
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
18 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
19 |
val metisN : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
20 |
val full_typesN : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
21 |
val partial_typesN : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
22 |
val no_typesN : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
23 |
val really_full_type_enc : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
24 |
val full_type_enc : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
25 |
val partial_type_enc : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
26 |
val no_type_enc : string |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
27 |
val full_type_encs : string list |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
28 |
val partial_type_encs : string list |
54500 | 29 |
val default_metis_lam_trans : string |
54772 | 30 |
|
49983
33e18e9916a8
use metaquantification when possible in Isar proofs
blanchet
parents:
49914
diff
changeset
|
31 |
val forall_of : term -> term -> term |
33e18e9916a8
use metaquantification when possible in Isar proofs
blanchet
parents:
49914
diff
changeset
|
32 |
val exists_of : term -> term -> term |
57765 | 33 |
val rename_bound_vars : term -> term |
55285 | 34 |
val type_enc_aliases : (string * string list) list |
45519
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
35 |
val unalias_type_enc : string -> string list |
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
36 |
val term_of_atp : Proof.context -> ATP_Problem.atp_format -> ATP_Problem_Generate.type_enc -> |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
37 |
bool -> int Symtab.table -> typ option -> (string, string atp_type) atp_term -> term |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
38 |
val prop_of_atp : Proof.context -> ATP_Problem.atp_format -> ATP_Problem_Generate.type_enc -> |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
39 |
bool -> int Symtab.table -> |
54811 | 40 |
(string, string, (string, string atp_type) atp_term, string) atp_formula -> term |
54499 | 41 |
|
57263 | 42 |
val used_facts_in_atp_proof : Proof.context -> (string * stature) list -> string atp_proof -> |
43 |
(string * stature) list |
|
44 |
val used_facts_in_unsound_atp_proof : Proof.context -> (string * stature) list -> 'a atp_proof -> |
|
45 |
string list option |
|
55257 | 46 |
val atp_proof_prefers_lifting : string atp_proof -> bool |
54500 | 47 |
val is_typed_helper_used_in_atp_proof : string atp_proof -> bool |
54772 | 48 |
val replace_dependencies_in_line : atp_step_name * atp_step_name list -> ('a, 'b) atp_step -> |
49 |
('a, 'b) atp_step |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
50 |
val termify_atp_proof : Proof.context -> string -> ATP_Problem.atp_format -> |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
51 |
ATP_Problem_Generate.type_enc -> string Symtab.table -> (string * term) list -> |
54499 | 52 |
int Symtab.table -> string atp_proof -> (term, string) atp_step list |
57267
8b87114357bd
integrated new Waldmeister code with 'sledgehammer' command
blanchet
parents:
57263
diff
changeset
|
53 |
val repair_waldmeister_endgame : (term, 'a) atp_step list -> (term, 'a) atp_step list |
57699 | 54 |
val infer_formulas_types : Proof.context -> term list -> term list |
54772 | 55 |
val introduce_spass_skolem : (term, string) atp_step list -> (term, string) atp_step list |
57263 | 56 |
val factify_atp_proof : (string * 'a) list -> term list -> term -> (term, string) atp_step list -> |
57 |
(term, string) atp_step list |
|
24425
ca97c6f3d9cd
Returning both a "one-line" proof and a structured proof
paulson
parents:
24387
diff
changeset
|
58 |
end; |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
59 |
|
46320 | 60 |
structure ATP_Proof_Reconstruct : ATP_PROOF_RECONSTRUCT = |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
61 |
struct |
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
62 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
63 |
open ATP_Util |
38028 | 64 |
open ATP_Problem |
39452 | 65 |
open ATP_Proof |
46320 | 66 |
open ATP_Problem_Generate |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
67 |
|
45519
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
68 |
val metisN = "metis" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
69 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
70 |
val full_typesN = "full_types" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
71 |
val partial_typesN = "partial_types" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
72 |
val no_typesN = "no_types" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
73 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
74 |
val really_full_type_enc = "mono_tags" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
75 |
val full_type_enc = "poly_guards_query" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
76 |
val partial_type_enc = "poly_args" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
77 |
val no_type_enc = "erased" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
78 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
79 |
val full_type_encs = [full_type_enc, really_full_type_enc] |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
80 |
val partial_type_encs = partial_type_enc :: full_type_encs |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
81 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
82 |
val type_enc_aliases = |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
83 |
[(full_typesN, full_type_encs), |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
84 |
(partial_typesN, partial_type_encs), |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
85 |
(no_typesN, [no_type_enc])] |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
86 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
87 |
fun unalias_type_enc s = |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
88 |
AList.lookup (op =) type_enc_aliases s |> the_default [s] |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
89 |
|
54500 | 90 |
val default_metis_lam_trans = combsN |
45519
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
91 |
|
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
92 |
fun term_name' (Var ((s, _), _)) = perhaps (try Name.dest_skolem) s |
52034
11b48e7a4e7e
correctly 'repair' the monomorphization context for SMT solvers from Sledgehammer
blanchet
parents:
52031
diff
changeset
|
93 |
| term_name' _ = "" |
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
94 |
|
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
95 |
fun lambda' v = Term.lambda_name (term_name' v, v) |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
96 |
|
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
97 |
fun forall_of v t = HOLogic.all_const (fastype_of v) $ lambda' v t |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
98 |
fun exists_of v t = HOLogic.exists_const (fastype_of v) $ lambda' v t |
39425 | 99 |
|
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
|
100 |
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
|
101 |
let val ww = "'" ^ w in |
56254 | 102 |
TFree (ww, the_default @{sort type} (Variable.def_sort ctxt (ww, ~1))) |
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
|
103 |
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
|
104 |
|
57765 | 105 |
fun single_letter upper s = |
106 |
let val s' = if String.isPrefix "o" s orelse String.isPrefix "O" s then "z" else s in |
|
107 |
String.extract (Name.desymbolize (SOME upper) (Long_Name.base_name s'), 0, SOME 1) |
|
108 |
end |
|
109 |
||
110 |
fun var_name_of_typ (Type (@{type_name fun}, [_, T])) = |
|
111 |
if body_type T = HOLogic.boolT then "p" else "f" |
|
112 |
| var_name_of_typ (Type (@{type_name set}, [T])) = single_letter true (var_name_of_typ T) |
|
113 |
| var_name_of_typ (Type (s, Ts)) = |
|
114 |
if String.isSuffix "list" s then var_name_of_typ (the_single Ts) ^ "s" |
|
115 |
else single_letter false (Long_Name.base_name s) |
|
116 |
| var_name_of_typ (TFree (s, _)) = single_letter false (perhaps (try (unprefix "'")) s) |
|
117 |
| var_name_of_typ (TVar ((s, _), T)) = var_name_of_typ (TFree (s, T)) |
|
118 |
||
119 |
fun rename_bound_vars (t $ u) = rename_bound_vars t $ rename_bound_vars u |
|
120 |
| rename_bound_vars (Abs (_, T, t)) = Abs (var_name_of_typ T, T, rename_bound_vars t) |
|
121 |
| rename_bound_vars t = t |
|
122 |
||
54820 | 123 |
exception ATP_CLASS of string list |
54818 | 124 |
exception ATP_TYPE of string atp_type list |
54811 | 125 |
exception ATP_TERM of (string, string atp_type) atp_term list |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
52758
diff
changeset
|
126 |
exception ATP_FORMULA of |
54811 | 127 |
(string, string, (string, string atp_type) atp_term, string) atp_formula list |
37991 | 128 |
exception SAME of unit |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
129 |
|
54820 | 130 |
fun class_of_atp_class cls = |
131 |
(case unprefix_and_unascii class_prefix cls of |
|
132 |
SOME s => s |
|
133 |
| NONE => raise ATP_CLASS [cls]) |
|
134 |
||
54811 | 135 |
(* Type variables are given the basic sort "HOL.type". Some will later be constrained by information |
136 |
from type literals, or by type inference. *) |
|
54820 | 137 |
fun typ_of_atp_type ctxt (ty as AType ((a, clss), tys)) = |
57697
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
138 |
let val Ts = map (typ_of_atp_type ctxt) tys in |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
139 |
(case unprefix_and_unascii type_const_prefix a of |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
140 |
SOME b => Type (invert_const b, Ts) |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
141 |
| NONE => |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
142 |
if not (null tys) then |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
143 |
raise ATP_TYPE [ty] (* only "tconst"s have type arguments *) |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
144 |
else |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
145 |
(case unprefix_and_unascii tfree_prefix a of |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
146 |
SOME b => make_tfree ctxt b |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
147 |
| NONE => |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
148 |
(* The term could be an Isabelle variable or a variable from the ATP, say "X1" or "_5018". |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
149 |
Sometimes variables from the ATP are indistinguishable from Isabelle variables, which |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
150 |
forces us to use a type parameter in all cases. *) |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
151 |
Type_Infer.param 0 ("'" ^ perhaps (unprefix_and_unascii tvar_prefix) a, |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
152 |
(if null clss then @{sort type} else map class_of_atp_class clss)))) |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
153 |
end |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
154 |
| typ_of_atp_type ctxt (AFun (ty1, ty2)) = typ_of_atp_type ctxt ty1 --> typ_of_atp_type ctxt ty2 |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
155 |
|
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
156 |
fun atp_type_of_atp_term (ATerm ((s, _), us)) = |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
157 |
let val tys = map atp_type_of_atp_term us in |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
158 |
if s = tptp_fun_type then |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
159 |
(case tys of |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
160 |
[ty1, ty2] => AFun (ty1, ty2) |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
161 |
| _ => raise ATP_TYPE tys) |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
162 |
else |
44341963ade3
correctly translate THF functions from terms to types
blanchet
parents:
57635
diff
changeset
|
163 |
AType ((s, []), tys) |
37991 | 164 |
end |
54818 | 165 |
|
166 |
fun typ_of_atp_term ctxt = typ_of_atp_type ctxt o atp_type_of_atp_term |
|
167 |
||
54789 | 168 |
(* Type class literal applied to a type. Returns triple of polarity, class, type. *) |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
169 |
fun type_constraint_of_term ctxt (u as ATerm ((a, _), us)) = |
54818 | 170 |
(case (unprefix_and_unascii class_prefix a, map (typ_of_atp_term ctxt) us) of |
42606
0c76cf483899
show sorts not just types in Isar proofs + tuning
blanchet
parents:
42595
diff
changeset
|
171 |
(SOME b, [T]) => (b, T) |
54789 | 172 |
| _ => raise ATP_TERM [u]) |
38014 | 173 |
|
43907
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
174 |
(* Accumulate type constraints in a formula: negative type literals. *) |
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
| 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
|
178 |
| add_type_constraint _ _ = I |
38014 | 179 |
|
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
180 |
fun repair_var_name_raw s = |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
181 |
let |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
182 |
fun subscript_name s n = s ^ nat_subscript n |
50704 | 183 |
val s = s |> String.map Char.toLower |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
184 |
in |
54789 | 185 |
(case space_explode "_" s of |
186 |
[_] => |
|
187 |
(case take_suffix Char.isDigit (String.explode s) of |
|
188 |
(cs1 as _ :: _, cs2 as _ :: _) => |
|
189 |
subscript_name (String.implode cs1) (the (Int.fromString (String.implode cs2))) |
|
190 |
| (_, _) => s) |
|
191 |
| [s1, s2] => (case Int.fromString s2 of SOME n => subscript_name s1 n | NONE => s) |
|
192 |
| _ => s) |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
193 |
end |
43182
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
194 |
|
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
195 |
fun repair_var_name textual s = |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
196 |
(case unprefix_and_unascii schematic_var_prefix s of |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
197 |
SOME s => s |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
198 |
| NONE => s |> textual ? repair_var_name_raw) |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
199 |
|
54789 | 200 |
(* The number of type arguments of a constant, zero if it's monomorphic. For (instances of) Skolem |
201 |
pseudoconstants, this information is encoded in the constant name. *) |
|
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52034
diff
changeset
|
202 |
fun robust_const_num_type_args thy s = |
43907
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
203 |
if String.isPrefix skolem_const_prefix s then |
46711
f745bcc4a1e5
more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents:
46435
diff
changeset
|
204 |
s |> Long_Name.explode |> 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
|
205 |
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
|
206 |
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
|
207 |
else |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
208 |
(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
|
209 |
|
56254 | 210 |
fun slack_fastype_of t = fastype_of t handle TERM _ => Type_Infer.anyT @{sort type} |
43182
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
211 |
|
51192
4dc6bb65c3c3
slacker comparison for Skolems, to avoid trivial equations
blanchet
parents:
50704
diff
changeset
|
212 |
(* Cope with "tt(X) = X" atoms, where "X" is existentially quantified. *) |
4dc6bb65c3c3
slacker comparison for Skolems, to avoid trivial equations
blanchet
parents:
50704
diff
changeset
|
213 |
fun loose_aconv (Free (s, _), Free (s', _)) = s = s' |
4dc6bb65c3c3
slacker comparison for Skolems, to avoid trivial equations
blanchet
parents:
50704
diff
changeset
|
214 |
| loose_aconv (t, t') = t aconv t' |
4dc6bb65c3c3
slacker comparison for Skolems, to avoid trivial equations
blanchet
parents:
50704
diff
changeset
|
215 |
|
54772 | 216 |
val spass_skolem_prefix = "sk" (* "skc" or "skf" *) |
217 |
val vampire_skolem_prefix = "sK" |
|
50703
76a2e506c125
swap Vampire's Skolem arguments to bring them in line with what E and metis's new skolemizer do (helps Isar proof reconstruction in some cases)
blanchet
parents:
50693
diff
changeset
|
218 |
|
57257 | 219 |
fun var_index_of_textual textual = if textual then 0 else 1 |
220 |
||
221 |
fun quantify_over_var textual quant_of var_s var_T t = |
|
222 |
let |
|
223 |
val vars = ((var_s, var_index_of_textual textual), var_T) :: |
|
224 |
filter (fn ((s, _), _) => s = var_s) (Term.add_vars t []) |
|
225 |
val normTs = vars |> AList.group (op =) |> map (apsnd hd) |
|
226 |
fun norm_var_types (Var (x, T)) = |
|
227 |
Var (x, the_default T (AList.lookup (op =) normTs x)) |
|
228 |
| norm_var_types t = t |
|
229 |
in t |> map_aterms norm_var_types |> fold_rev quant_of (map Var normTs) end |
|
230 |
||
231 |
||
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
232 |
(* Higher-order translation. Variables are typed (although we don't use that information). Lambdas |
57256 | 233 |
are typed. |
234 |
||
235 |
The code is similar to term_of_atp_fo. *) |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
236 |
fun term_of_atp_ho ctxt textual sym_tab = |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
237 |
let |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
238 |
val thy = Proof_Context.theory_of ctxt |
57257 | 239 |
val var_index = var_index_of_textual textual |
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
240 |
|
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
241 |
fun do_term opt_T u = |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
242 |
(case u of |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
243 |
AAbs(((var, ty), term), []) => |
57257 | 244 |
let |
245 |
val typ = typ_of_atp_type ctxt ty |
|
246 |
val var_name = repair_var_name textual var |
|
247 |
val tm = do_term NONE term |
|
248 |
in quantify_over_var textual lambda' var_name typ tm end |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
249 |
| ATerm ((s, tys), us) => |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
250 |
if s = "" |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
251 |
then error "Isar proof reconstruction failed because the ATP proof \ |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
252 |
\contains unparsable material." |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
253 |
else if s = tptp_equal then |
57703 | 254 |
let |
255 |
val ts = map (do_term NONE) us |
|
256 |
fun equal_term ts = |
|
257 |
list_comb (Const (@{const_name HOL.eq}, Type_Infer.anyT @{sort type}), ts) |
|
258 |
in |
|
259 |
if textual then |
|
260 |
(case ts of |
|
57713 | 261 |
[t1, t2] => |
262 |
if loose_aconv (t1, t2) then |
|
57703 | 263 |
@{const True} |
57713 | 264 |
else if Term.aconv_untyped (t2, @{const True}) then |
265 |
t1 |
|
266 |
else if Term.aconv_untyped (t1, @{const True}) then |
|
267 |
t2 |
|
57703 | 268 |
else |
269 |
equal_term ts |
|
270 |
| _ => equal_term ts) |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
271 |
else |
57703 | 272 |
equal_term ts |
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
273 |
end |
57256 | 274 |
else if not (null us) then |
275 |
let |
|
276 |
val args = List.map (do_term NONE) us |
|
277 |
val opt_T' = SOME (map slack_fastype_of args ---> the_default dummyT opt_T) |
|
278 |
val func = do_term opt_T' (ATerm ((s, tys), [])) |
|
279 |
in foldl1 (op $) (func :: args) end |
|
280 |
else if s = tptp_or then HOLogic.disj |
|
281 |
else if s = tptp_and then HOLogic.conj |
|
282 |
else if s = tptp_implies then HOLogic.imp |
|
283 |
else if s = tptp_iff orelse s = tptp_equal then HOLogic.eq_const dummyT |
|
284 |
else if s = tptp_not_iff orelse s = tptp_not_equal then @{term "% P Q. Q ~= P"} |
|
285 |
else if s = tptp_if then @{term "% P Q. Q --> P"} |
|
286 |
else if s = tptp_not_and then @{term "% P Q. ~ (P & Q)"} |
|
287 |
else if s = tptp_not_or then @{term "% P Q. ~ (P | Q)"} |
|
288 |
else if s = tptp_not then HOLogic.Not |
|
289 |
else if s = tptp_ho_forall then HOLogic.all_const dummyT |
|
290 |
else if s = tptp_ho_exists then HOLogic.exists_const dummyT |
|
57709 | 291 |
else if s = tptp_hilbert_choice then HOLogic.choice_const dummyT |
292 |
else if s = tptp_hilbert_the then @{term "The"} |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
293 |
else |
57256 | 294 |
(case unprefix_and_unascii const_prefix s of |
295 |
SOME s' => |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
296 |
let |
57547
677b07d777c3
don't generate TPTP THF 'Definition's, because they complicate reconstruction for AgsyHOL and Satallax
blanchet
parents:
57267
diff
changeset
|
297 |
val ((s', _), mangled_us) = s' |> unmangled_const |>> `invert_const |
57256 | 298 |
val num_ty_args = length us - the_default 0 (Symtab.lookup sym_tab s) |
299 |
val (type_us, term_us) = chop num_ty_args us |>> append mangled_us |
|
300 |
val term_ts = map (do_term NONE) term_us |
|
301 |
val Ts = map (typ_of_atp_type ctxt) tys @ map (typ_of_atp_term ctxt) type_us |
|
302 |
val T = |
|
303 |
(if not (null Ts) andalso robust_const_num_type_args thy s' = length Ts then |
|
304 |
if textual then try (Sign.const_instance thy) (s', Ts) else NONE |
|
305 |
else |
|
306 |
NONE) |
|
307 |
|> (fn SOME T => T |
|
308 |
| NONE => |
|
309 |
map slack_fastype_of term_ts ---> |
|
310 |
the_default (Type_Infer.anyT @{sort type}) opt_T) |
|
311 |
val t = Const (unproxify_const s', T) |
|
312 |
in list_comb (t, term_ts) end |
|
313 |
| NONE => (* a free or schematic variable *) |
|
314 |
let |
|
315 |
fun fresh_up s = |
|
316 |
[(s, ())] |> Variable.variant_frees ctxt [] |> hd |> fst |
|
317 |
val ts = map (do_term NONE) us |
|
318 |
val T = |
|
319 |
(case opt_T of |
|
320 |
SOME T => map slack_fastype_of ts ---> T |
|
321 |
| NONE => |
|
322 |
map slack_fastype_of ts ---> |
|
323 |
(case tys of |
|
324 |
[ty] => typ_of_atp_type ctxt ty |
|
325 |
| _ => Type_Infer.anyT @{sort type})) |
|
326 |
val t = |
|
327 |
(case unprefix_and_unascii fixed_var_prefix s of |
|
328 |
SOME s => Free (s, T) |
|
329 |
| NONE => |
|
330 |
if textual andalso not (is_tptp_variable s) then |
|
331 |
Free (s |> textual ? (repair_var_name_raw #> fresh_up), T) |
|
332 |
else |
|
333 |
Var ((repair_var_name textual s, var_index), T)) |
|
334 |
in list_comb (t, ts) end)) |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
335 |
in do_term end |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
336 |
|
56254 | 337 |
(* First-order translation. No types are known for variables. "Type_Infer.anyT @{sort type}" |
338 |
should allow them to be inferred. *) |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
339 |
fun term_of_atp_fo ctxt textual sym_tab = |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
340 |
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
|
341 |
val thy = Proof_Context.theory_of ctxt |
54789 | 342 |
(* For Metis, we use 1 rather than 0 because variable references in clauses may otherwise |
343 |
conflict with variable constraints in the goal. At least, type inference often fails |
|
344 |
otherwise. See also "axiom_inference" in "Metis_Reconstruct". *) |
|
57257 | 345 |
val var_index = var_index_of_textual textual |
57199 | 346 |
|
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
347 |
fun do_term extra_ts opt_T u = |
54789 | 348 |
(case u of |
54818 | 349 |
ATerm ((s, tys), us) => |
57199 | 350 |
if s = "" then |
351 |
error "Isar proof reconstruction failed because the ATP proof contains unparsable \ |
|
352 |
\material." |
|
51878 | 353 |
else if String.isPrefix native_type_prefix s then |
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42943
diff
changeset
|
354 |
@{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
|
355 |
else if s = tptp_equal then |
43093 | 356 |
let val ts = map (do_term [] NONE) us in |
54822 | 357 |
if textual andalso length ts = 2 andalso loose_aconv (hd ts, List.last ts) then |
39106 | 358 |
@{const True} |
359 |
else |
|
56254 | 360 |
list_comb (Const (@{const_name HOL.eq}, Type_Infer.anyT @{sort type}), ts) |
39106 | 361 |
end |
54789 | 362 |
else |
363 |
(case unprefix_and_unascii const_prefix s of |
|
364 |
SOME s' => |
|
54818 | 365 |
let val ((s', s''), mangled_us) = s' |> unmangled_const |>> `invert_const in |
54789 | 366 |
if s' = type_tag_name then |
367 |
(case mangled_us @ us of |
|
54818 | 368 |
[typ_u, term_u] => do_term extra_ts (SOME (typ_of_atp_term ctxt typ_u)) term_u |
54789 | 369 |
| _ => raise ATP_TERM us) |
370 |
else if s' = predicator_name then |
|
371 |
do_term [] (SOME @{typ bool}) (hd us) |
|
372 |
else if s' = app_op_name then |
|
373 |
let val extra_t = do_term [] NONE (List.last us) in |
|
374 |
do_term (extra_t :: extra_ts) |
|
57199 | 375 |
(case opt_T of SOME T => SOME (slack_fastype_of extra_t --> T) | NONE => NONE) |
376 |
(nth us (length us - 2)) |
|
54789 | 377 |
end |
378 |
else if s' = type_guard_name then |
|
379 |
@{const True} (* ignore type predicates *) |
|
380 |
else |
|
381 |
let |
|
382 |
val new_skolem = String.isPrefix new_skolem_const_prefix s'' |
|
54818 | 383 |
val num_ty_args = length us - the_default 0 (Symtab.lookup sym_tab s) |
384 |
val (type_us, term_us) = chop num_ty_args us |>> append mangled_us |
|
54789 | 385 |
val term_ts = map (do_term [] NONE) term_us |
54818 | 386 |
|
387 |
val Ts = map (typ_of_atp_type ctxt) tys @ map (typ_of_atp_term ctxt) type_us |
|
54789 | 388 |
val T = |
54818 | 389 |
(if not (null Ts) andalso robust_const_num_type_args thy s' = length Ts then |
57199 | 390 |
if new_skolem then SOME (Type_Infer.paramify_vars (tl Ts ---> hd Ts)) |
391 |
else if textual then try (Sign.const_instance thy) (s', Ts) |
|
392 |
else NONE |
|
54789 | 393 |
else |
394 |
NONE) |
|
395 |
|> (fn SOME T => T |
|
396 |
| NONE => |
|
56254 | 397 |
map slack_fastype_of term_ts ---> |
57199 | 398 |
the_default (Type_Infer.anyT @{sort type}) opt_T) |
54789 | 399 |
val t = |
400 |
if new_skolem then Var ((new_skolem_var_name_of_const s'', var_index), T) |
|
401 |
else Const (unproxify_const s', T) |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
402 |
in |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
403 |
list_comb (t, term_ts @ extra_ts) |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
404 |
end |
54789 | 405 |
end |
406 |
| NONE => (* a free or schematic variable *) |
|
407 |
let |
|
408 |
(* This assumes that distinct names are mapped to distinct names by |
|
54822 | 409 |
"Variable.variant_frees". This does not hold in general but should hold for |
410 |
ATP-generated Skolem function names, since these end with a digit and |
|
411 |
"variant_frees" appends letters. *) |
|
57199 | 412 |
fun fresh_up s = [(s, ())] |> Variable.variant_frees ctxt [] |> hd |> fst |
413 |
||
54789 | 414 |
val term_ts = |
415 |
map (do_term [] NONE) us |
|
416 |
(* SPASS (3.8ds) and Vampire (2.6) pass arguments to Skolem functions in reverse |
|
57699 | 417 |
order, which is incompatible with "metis"'s new skolemizer. *) |
54789 | 418 |
|> exists (fn pre => String.isPrefix pre s) |
419 |
[spass_skolem_prefix, vampire_skolem_prefix] ? rev |
|
420 |
val ts = term_ts @ extra_ts |
|
421 |
val T = |
|
422 |
(case opt_T of |
|
423 |
SOME T => map slack_fastype_of term_ts ---> T |
|
54822 | 424 |
| NONE => |
425 |
map slack_fastype_of ts ---> |
|
56254 | 426 |
(case tys of [ty] => typ_of_atp_type ctxt ty | _ => Type_Infer.anyT @{sort type})) |
54789 | 427 |
val t = |
428 |
(case unprefix_and_unascii fixed_var_prefix s of |
|
429 |
SOME s => Free (s, T) |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
430 |
| NONE => |
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
431 |
if textual andalso not (is_tptp_variable s) then |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
432 |
Free (s |> textual ? (repair_var_name_raw #> fresh_up), T) |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
433 |
else |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
434 |
Var ((repair_var_name textual s, var_index), T)) |
54789 | 435 |
in list_comb (t, ts) end)) |
43093 | 436 |
in do_term [] end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
437 |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
438 |
fun term_of_atp ctxt (ATP_Problem.THF _) type_enc = |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
439 |
if ATP_Problem_Generate.is_type_enc_higher_order type_enc |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
440 |
then term_of_atp_ho ctxt |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
441 |
else error "Unsupported Isar reconstruction." |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
442 |
| term_of_atp ctxt _ type_enc = |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
443 |
if not (ATP_Problem_Generate.is_type_enc_higher_order type_enc) |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
444 |
then term_of_atp_fo ctxt |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
445 |
else error "Unsupported Isar reconstruction." |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
446 |
|
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
447 |
fun term_of_atom ctxt format type_enc textual sym_tab pos (u as ATerm ((s, _), _)) = |
38014 | 448 |
if String.isPrefix class_prefix s then |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
449 |
add_type_constraint pos (type_constraint_of_term ctxt u) |
38014 | 450 |
#> pair @{const True} |
451 |
else |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
452 |
pair (term_of_atp ctxt format type_enc 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
|
453 |
|
37991 | 454 |
(* Update schematic type variables with detected sort constraints. It's not |
42563 | 455 |
totally clear whether this code is necessary. *) |
38014 | 456 |
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
|
457 |
let |
37991 | 458 |
fun do_type (Type (a, Ts)) = Type (a, map do_type Ts) |
459 |
| do_type (TVar (xi, s)) = |
|
460 |
TVar (xi, the_default s (Vartab.lookup tvar_tab xi)) |
|
461 |
| do_type (TFree z) = TFree z |
|
462 |
fun do_term (Const (a, T)) = Const (a, do_type T) |
|
463 |
| do_term (Free (a, T)) = Free (a, do_type T) |
|
464 |
| do_term (Var (xi, T)) = Var (xi, do_type T) |
|
465 |
| do_term (t as Bound _) = t |
|
466 |
| do_term (Abs (a, T, t)) = Abs (a, do_type T, do_term t) |
|
467 |
| do_term (t1 $ t2) = do_term t1 $ do_term t2 |
|
468 |
in t |> not (Vartab.is_empty tvar_tab) ? do_term end |
|
469 |
||
54811 | 470 |
(* Interpret an ATP formula as a HOL term, extracting sort constraints as they appear in the |
471 |
formula. *) |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
472 |
fun prop_of_atp ctxt format type_enc textual sym_tab phi = |
38014 | 473 |
let |
474 |
fun do_formula pos phi = |
|
54789 | 475 |
(case phi of |
38014 | 476 |
AQuant (_, [], phi) => do_formula pos phi |
42526 | 477 |
| AQuant (q, (s, _) :: xs, phi') => |
38014 | 478 |
do_formula pos (AQuant (q, xs, phi')) |
42526 | 479 |
(* FIXME: TFF *) |
57257 | 480 |
#>> quantify_over_var textual (case q of AForall => forall_of | AExists => exists_of) |
481 |
(repair_var_name textual s) dummyT |
|
38014 | 482 |
| AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not |
37991 | 483 |
| AConn (c, [phi1, phi2]) => |
38014 | 484 |
do_formula (pos |> c = AImplies ? not) phi1 |
485 |
##>> do_formula pos phi2 |
|
486 |
#>> (case c of |
|
54811 | 487 |
AAnd => s_conj |
488 |
| AOr => s_disj |
|
489 |
| AImplies => s_imp |
|
490 |
| AIff => s_iff |
|
491 |
| ANot => raise Fail "impossible connective") |
|
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
492 |
| AAtom tm => term_of_atom ctxt format type_enc textual sym_tab pos tm |
54789 | 493 |
| _ => raise ATP_FORMULA [phi]) |
494 |
in |
|
495 |
repair_tvar_sorts (do_formula true phi Vartab.empty) |
|
496 |
end |
|
37991 | 497 |
|
54500 | 498 |
val unprefix_fact_number = space_implode "_" o tl o space_explode "_" |
499 |
||
57263 | 500 |
fun resolve_fact facts s = |
54789 | 501 |
(case try (unprefix fact_prefix) s of |
54500 | 502 |
SOME s' => |
503 |
let val s' = s' |> unprefix_fact_number |> unascii_of in |
|
57263 | 504 |
AList.lookup (op =) facts s' |> Option.map (pair s') |
54500 | 505 |
end |
54789 | 506 |
| NONE => NONE) |
54506 | 507 |
|
57263 | 508 |
fun resolve_conjecture s = |
54789 | 509 |
(case try (unprefix conjecture_prefix) s of |
54500 | 510 |
SOME s' => Int.fromString s' |
54789 | 511 |
| NONE => NONE) |
54500 | 512 |
|
57263 | 513 |
fun resolve_facts facts = map_filter (resolve_fact facts) |
514 |
val resolve_conjectures = map_filter resolve_conjecture |
|
54500 | 515 |
|
516 |
fun is_axiom_used_in_proof pred = |
|
517 |
exists (fn ((_, ss), _, _, _, []) => exists pred ss | _ => false) |
|
518 |
||
519 |
val leo2_extcnf_equal_neg_rule = "extcnf_equal_neg" |
|
520 |
||
57263 | 521 |
fun add_fact ctxt facts ((_, ss), _, _, rule, deps) = |
57707
0242e9578828
imported patch satallax_proof_support_Sledgehammer
fleury
parents:
57703
diff
changeset
|
522 |
(if member (op =) [agsyhol_core_rule, leo2_extcnf_equal_neg_rule] rule then |
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
55285
diff
changeset
|
523 |
insert (op =) (short_thm_name ctxt ext, (Global, General)) |
54500 | 524 |
else |
525 |
I) |
|
57263 | 526 |
#> (if null deps then union (op =) (resolve_facts facts ss) else I) |
54500 | 527 |
|
57263 | 528 |
fun used_facts_in_atp_proof ctxt facts atp_proof = |
529 |
if null atp_proof then facts else fold (add_fact ctxt facts) atp_proof [] |
|
54500 | 530 |
|
531 |
fun used_facts_in_unsound_atp_proof _ _ [] = NONE |
|
57263 | 532 |
| used_facts_in_unsound_atp_proof ctxt facts atp_proof = |
533 |
let val used_facts = used_facts_in_atp_proof ctxt facts atp_proof in |
|
54500 | 534 |
if forall (fn (_, (sc, _)) => sc = Global) used_facts andalso |
57263 | 535 |
not (is_axiom_used_in_proof (is_some o resolve_conjecture) atp_proof) then |
54500 | 536 |
SOME (map fst used_facts) |
537 |
else |
|
538 |
NONE |
|
539 |
end |
|
540 |
||
541 |
val ascii_of_lam_fact_prefix = ascii_of lam_fact_prefix |
|
542 |
||
543 |
(* overapproximation (good enough) *) |
|
544 |
fun is_lam_lifted s = |
|
545 |
String.isPrefix fact_prefix s andalso |
|
546 |
String.isSubstring ascii_of_lam_fact_prefix s |
|
547 |
||
548 |
val is_combinator_def = String.isPrefix (helper_prefix ^ combinator_prefix) |
|
549 |
||
55257 | 550 |
fun atp_proof_prefers_lifting atp_proof = |
551 |
(is_axiom_used_in_proof is_combinator_def atp_proof, |
|
552 |
is_axiom_used_in_proof is_lam_lifted atp_proof) = (false, true) |
|
54500 | 553 |
|
554 |
val is_typed_helper_name = |
|
555 |
String.isPrefix helper_prefix andf String.isSuffix typed_helper_suffix |
|
556 |
||
557 |
fun is_typed_helper_used_in_atp_proof atp_proof = |
|
558 |
is_axiom_used_in_proof is_typed_helper_name atp_proof |
|
559 |
||
54772 | 560 |
fun replace_one_dependency (old, new) dep = if is_same_atp_step dep old then new else [dep] |
561 |
fun replace_dependencies_in_line old_new (name, role, t, rule, deps) = |
|
562 |
(name, role, t, rule, fold (union (op =) o replace_one_dependency old_new) deps []) |
|
563 |
||
54499 | 564 |
fun repair_name "$true" = "c_True" |
565 |
| repair_name "$false" = "c_False" |
|
566 |
| repair_name "$$e" = tptp_equal (* seen in Vampire proofs *) |
|
567 |
| repair_name s = |
|
568 |
if is_tptp_equal s orelse |
|
569 |
(* seen in Vampire proofs *) |
|
570 |
(String.isPrefix "sQ" s andalso String.isSuffix "_eqProxy" s) then |
|
571 |
tptp_equal |
|
572 |
else |
|
573 |
s |
|
574 |
||
57699 | 575 |
fun set_var_index j = map_aterms (fn Var ((s, 0), T) => Var ((s, j), T) | t => t) |
57635
97adb86619a4
more robust handling of types for skolems (modeled as Frees)
blanchet
parents:
57547
diff
changeset
|
576 |
|
57699 | 577 |
fun infer_formulas_types ctxt = |
57635
97adb86619a4
more robust handling of types for skolems (modeled as Frees)
blanchet
parents:
57547
diff
changeset
|
578 |
map_index (uncurry (fn j => set_var_index j #> Type.constraint HOLogic.boolT)) |
97adb86619a4
more robust handling of types for skolems (modeled as Frees)
blanchet
parents:
57547
diff
changeset
|
579 |
#> Syntax.check_terms (Proof_Context.set_mode Proof_Context.mode_schematic ctxt) |
97adb86619a4
more robust handling of types for skolems (modeled as Frees)
blanchet
parents:
57547
diff
changeset
|
580 |
#> map (set_var_index 0) |
54499 | 581 |
|
582 |
val combinator_table = |
|
583 |
[(@{const_name Meson.COMBI}, @{thm Meson.COMBI_def [abs_def]}), |
|
584 |
(@{const_name Meson.COMBK}, @{thm Meson.COMBK_def [abs_def]}), |
|
585 |
(@{const_name Meson.COMBB}, @{thm Meson.COMBB_def [abs_def]}), |
|
586 |
(@{const_name Meson.COMBC}, @{thm Meson.COMBC_def [abs_def]}), |
|
587 |
(@{const_name Meson.COMBS}, @{thm Meson.COMBS_def [abs_def]})] |
|
588 |
||
589 |
fun uncombine_term thy = |
|
590 |
let |
|
57717
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
591 |
fun uncomb (t1 $ t2) = betapply (uncomb t1, uncomb t2) |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
592 |
| uncomb (Abs (s, T, t)) = Abs (s, T, uncomb t) |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
593 |
| uncomb (t as Const (x as (s, _))) = |
54499 | 594 |
(case AList.lookup (op =) combinator_table s of |
54756 | 595 |
SOME thm => thm |> prop_of |> specialize_type thy x |> Logic.dest_equals |> snd |
596 |
| NONE => t) |
|
57717
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
597 |
| uncomb t = t |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
598 |
in uncomb end |
54499 | 599 |
|
57717
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
600 |
fun unlift_aterm lifted (t as Const (s, _)) = |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
601 |
if String.isPrefix lam_lifted_prefix s then |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
602 |
(* FIXME: do something about the types *) |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
603 |
(case AList.lookup (op =) lifted s of |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
604 |
SOME t' => unlift_term lifted t' |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
605 |
| NONE => t) |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
606 |
else |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
607 |
t |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
608 |
| unlift_aterm _ t = t |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
609 |
and unlift_term lifted = |
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
610 |
map_aterms (unlift_aterm lifted) |
54499 | 611 |
|
57256 | 612 |
fun termify_line _ _ _ _ _ (_, Type_Role, _, _, _) = NONE |
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
613 |
| termify_line ctxt format type_enc lifted sym_tab (name, role, u, rule, deps) = |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
614 |
let |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
615 |
val thy = Proof_Context.theory_of ctxt |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
616 |
val t = u |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
617 |
|> prop_of_atp ctxt format type_enc true sym_tab |
57717
949838aba487
unlift before uncombine, because the definition of a lambda-lifted symbol might have an SK combinator in it (in hybrid encodings)
blanchet
parents:
57713
diff
changeset
|
618 |
|> unlift_term lifted |
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
619 |
|> uncombine_term thy |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
620 |
in |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
621 |
SOME (name, role, t, rule, deps) |
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
622 |
end |
54499 | 623 |
|
624 |
val waldmeister_conjecture_num = "1.0.0.0" |
|
625 |
||
54756 | 626 |
fun repair_waldmeister_endgame proof = |
54499 | 627 |
let |
56854 | 628 |
fun repair_tail (name, _, @{const Trueprop} $ t, rule, deps) = |
629 |
(name, Negated_Conjecture, @{const Trueprop} $ s_not t, rule, deps) |
|
54756 | 630 |
fun repair_body [] = [] |
631 |
| repair_body ((line as ((num, _), _, _, _, _)) :: lines) = |
|
632 |
if num = waldmeister_conjecture_num then map repair_tail (line :: lines) |
|
633 |
else line :: repair_body lines |
|
634 |
in |
|
635 |
repair_body proof |
|
636 |
end |
|
54499 | 637 |
|
57635
97adb86619a4
more robust handling of types for skolems (modeled as Frees)
blanchet
parents:
57547
diff
changeset
|
638 |
fun map_proof_terms f (lines : ('a * 'b * 'c * 'd * 'e) list) = |
97adb86619a4
more robust handling of types for skolems (modeled as Frees)
blanchet
parents:
57547
diff
changeset
|
639 |
map2 (fn c => fn (a, b, _, d, e) => (a, b, c, d, e)) (f (map #3 lines)) lines |
97adb86619a4
more robust handling of types for skolems (modeled as Frees)
blanchet
parents:
57547
diff
changeset
|
640 |
|
57258
67d85a8aa6cc
Moving the remote prefix deleting on Sledgehammer's side
fleury
parents:
57257
diff
changeset
|
641 |
fun termify_atp_proof ctxt local_prover format type_enc pool lifted sym_tab = |
57267
8b87114357bd
integrated new Waldmeister code with 'sledgehammer' command
blanchet
parents:
57263
diff
changeset
|
642 |
nasty_atp_proof pool |
54499 | 643 |
#> map_term_names_in_atp_proof repair_name |
57255
488046fdda59
add support for Isar reconstruction for thf1 ATP provers like Leo-II.
fleury
parents:
57199
diff
changeset
|
644 |
#> map_filter (termify_line ctxt format type_enc lifted sym_tab) |
57699 | 645 |
#> map_proof_terms (infer_formulas_types ctxt #> map HOLogic.mk_Trueprop) |
57258
67d85a8aa6cc
Moving the remote prefix deleting on Sledgehammer's side
fleury
parents:
57257
diff
changeset
|
646 |
#> local_prover = waldmeisterN ? repair_waldmeister_endgame |
54499 | 647 |
|
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
648 |
fun take_distinct_vars seen ((t as Var _) :: ts) = |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
649 |
if member (op aconv) seen t then rev seen else take_distinct_vars (t :: seen) ts |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
650 |
| take_distinct_vars seen _ = rev seen |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
651 |
|
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
652 |
fun unskolemize_term skos t = |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
653 |
let |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
654 |
val is_sko = member (op =) skos |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
655 |
|
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
656 |
fun find_args args (t $ u) = find_args (u :: args) t #> find_args [] u |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
657 |
| find_args _ (Abs (_, _, t)) = find_args [] t |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
658 |
| find_args args (Free (s, _)) = |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
659 |
if is_sko s then |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
660 |
let val new = take_distinct_vars [] args in |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
661 |
(fn [] => new | old => if length new < length old then new else old) |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
662 |
end |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
663 |
else |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
664 |
I |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
665 |
| find_args _ _ = I |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
666 |
|
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
667 |
val alls = find_args [] t [] |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
668 |
val num_alls = length alls |
55195 | 669 |
|
670 |
fun fix_skos args (t $ u) = fix_skos (fix_skos [] u :: args) t |
|
671 |
| fix_skos args (t as Free (s, T)) = |
|
672 |
if is_sko s then list_comb (Free (s, funpow num_alls body_type T), drop num_alls args) |
|
673 |
else list_comb (t, args) |
|
674 |
| fix_skos [] (Abs (s, T, t)) = Abs (s, T, fix_skos [] t) |
|
675 |
| fix_skos [] t = t |
|
676 |
| fix_skos args t = list_comb (fix_skos [] t, args) |
|
677 |
||
678 |
val t' = fix_skos [] t |
|
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
679 |
|
55195 | 680 |
fun add_sko (t as Free (s, _)) = is_sko s ? insert (op aconv) t |
681 |
| add_sko _ = I |
|
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
682 |
|
55195 | 683 |
val exs = Term.fold_aterms add_sko t' [] |
684 |
in |
|
685 |
t' |
|
686 |
|> HOLogic.dest_Trueprop |
|
687 |
|> fold exists_of exs |> Term.map_abs_vars (K Name.uu) |
|
688 |
|> fold_rev forall_of alls |
|
689 |
|> HOLogic.mk_Trueprop |
|
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
690 |
end |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
691 |
|
54772 | 692 |
fun introduce_spass_skolem [] = [] |
693 |
| introduce_spass_skolem (proof as (_, _, _, rule1, _) :: _) = |
|
694 |
if rule1 = spass_input_rule then |
|
695 |
let |
|
696 |
fun add_sko (Free (s, _)) = String.isPrefix spass_skolem_prefix s ? insert (op =) s |
|
697 |
| add_sko _ = I |
|
698 |
||
699 |
(* union-find would be faster *) |
|
54799 | 700 |
fun add_cycle [] = I |
701 |
| add_cycle ss = |
|
54772 | 702 |
fold (fn s => Graph.default_node (s, ())) ss |
703 |
#> fold Graph.add_edge (ss ~~ tl ss @ [hd ss]) |
|
704 |
||
705 |
val (input_steps, other_steps) = List.partition (null o #5) proof |
|
706 |
||
707 |
val skoss = map (fn (_, _, t, _, _) => Term.fold_aterms add_sko t []) input_steps |
|
708 |
val skoss_input_steps = filter_out (null o fst) (skoss ~~ input_steps) |
|
54799 | 709 |
val groups = Graph.strong_conn (fold add_cycle skoss Graph.empty) |
54772 | 710 |
|
711 |
fun step_name_of_group skos = (implode skos, []) |
|
712 |
fun in_group group = member (op =) group o hd |
|
713 |
fun group_of sko = the (find_first (fn group => in_group group sko) groups) |
|
714 |
||
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
715 |
fun new_steps (skoss_steps : (string list * (term, 'a) atp_step) list) group = |
54772 | 716 |
let |
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
717 |
val name = step_name_of_group group |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
718 |
val name0 = name |>> prefix "0" |
54772 | 719 |
val t = |
720 |
skoss_steps |
|
721 |
|> map (snd #> #3 #> HOLogic.dest_Trueprop) |
|
722 |
|> Library.foldr1 s_conj |
|
723 |
|> HOLogic.mk_Trueprop |
|
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
724 |
val skos = fold (union (op =) o fst) skoss_steps [] |
54772 | 725 |
val deps = map (snd #> #1) skoss_steps |
726 |
in |
|
55195 | 727 |
[(name0, Unknown, unskolemize_term skos t, spass_pre_skolemize_rule, deps), |
728 |
(name, Unknown, t, spass_skolemize_rule, [name0])] |
|
54772 | 729 |
end |
730 |
||
731 |
val sko_steps = |
|
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
732 |
maps (fn group => new_steps (filter (in_group group o fst) skoss_input_steps) group) |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
733 |
groups |
54772 | 734 |
|
735 |
val old_news = |
|
736 |
map (fn (skos, (name, _, _, _, _)) => (name, [step_name_of_group (group_of skos)])) |
|
737 |
skoss_input_steps |
|
738 |
val repair_deps = fold replace_dependencies_in_line old_news |
|
739 |
in |
|
740 |
input_steps @ sko_steps @ map repair_deps other_steps |
|
741 |
end |
|
742 |
else |
|
743 |
proof |
|
744 |
||
57263 | 745 |
fun factify_atp_proof facts hyp_ts concl_t atp_proof = |
54505 | 746 |
let |
54799 | 747 |
fun factify_step ((num, ss), _, t, rule, deps) = |
54505 | 748 |
let |
749 |
val (ss', role', t') = |
|
57263 | 750 |
(case resolve_conjectures ss of |
54505 | 751 |
[j] => |
752 |
if j = length hyp_ts then ([], Conjecture, concl_t) else ([], Hypothesis, nth hyp_ts j) |
|
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
753 |
| _ => |
57263 | 754 |
(case resolve_facts facts ss of |
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
755 |
[] => (ss, Plain, t) |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
756 |
| facts => (map fst facts, Axiom, t))) |
54505 | 757 |
in |
758 |
((num, ss'), role', t', rule, deps) |
|
759 |
end |
|
760 |
||
761 |
val atp_proof = map factify_step atp_proof |
|
762 |
val names = map #1 atp_proof |
|
763 |
||
764 |
fun repair_dep (num, ss) = (num, the_default ss (AList.lookup (op =) names num)) |
|
765 |
fun repair_deps (name, role, t, rule, deps) = (name, role, t, rule, map repair_dep deps) |
|
54772 | 766 |
in |
767 |
map repair_deps atp_proof |
|
768 |
end |
|
54505 | 769 |
|
31038 | 770 |
end; |