author | blanchet |
Tue, 10 Jun 2014 11:38:53 +0200 | |
changeset 57199 | 472360558b22 |
parent 56854 | ddd3af5a683d |
child 57255 | 488046fdda59 |
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 |
55285 | 33 |
val type_enc_aliases : (string * string list) list |
45519
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
34 |
val unalias_type_enc : string -> string list |
54507 | 35 |
val term_of_atp : Proof.context -> bool -> int Symtab.table -> typ option -> |
54811 | 36 |
(string, string atp_type) atp_term -> term |
54507 | 37 |
val prop_of_atp : Proof.context -> bool -> int Symtab.table -> |
54811 | 38 |
(string, string, (string, string atp_type) atp_term, string) atp_formula -> term |
54499 | 39 |
|
54500 | 40 |
val used_facts_in_atp_proof : |
54507 | 41 |
Proof.context -> (string * stature) list vector -> string atp_proof -> (string * stature) list |
42 |
val used_facts_in_unsound_atp_proof : Proof.context -> (string * stature) list vector -> |
|
43 |
'a atp_proof -> string list option |
|
55257 | 44 |
val atp_proof_prefers_lifting : string atp_proof -> bool |
54500 | 45 |
val is_typed_helper_used_in_atp_proof : string atp_proof -> bool |
54772 | 46 |
val replace_dependencies_in_line : atp_step_name * atp_step_name list -> ('a, 'b) atp_step -> |
47 |
('a, 'b) atp_step |
|
54505 | 48 |
val termify_atp_proof : Proof.context -> string Symtab.table -> (string * term) list -> |
54499 | 49 |
int Symtab.table -> string atp_proof -> (term, string) atp_step list |
54772 | 50 |
val introduce_spass_skolem : (term, string) atp_step list -> (term, string) atp_step list |
54505 | 51 |
val factify_atp_proof : (string * 'a) list vector -> term list -> term -> |
52 |
(term, string) atp_step list -> (term, string) atp_step list |
|
24425
ca97c6f3d9cd
Returning both a "one-line" proof and a structured proof
paulson
parents:
24387
diff
changeset
|
53 |
end; |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
54 |
|
46320 | 55 |
structure ATP_Proof_Reconstruct : ATP_PROOF_RECONSTRUCT = |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
56 |
struct |
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
57 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43062
diff
changeset
|
58 |
open ATP_Util |
38028 | 59 |
open ATP_Problem |
39452 | 60 |
open ATP_Proof |
46320 | 61 |
open ATP_Problem_Generate |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
62 |
|
45519
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
63 |
val metisN = "metis" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
64 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
65 |
val full_typesN = "full_types" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
66 |
val partial_typesN = "partial_types" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
67 |
val no_typesN = "no_types" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
68 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
69 |
val really_full_type_enc = "mono_tags" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
70 |
val full_type_enc = "poly_guards_query" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
71 |
val partial_type_enc = "poly_args" |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
72 |
val no_type_enc = "erased" |
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 full_type_encs = [full_type_enc, really_full_type_enc] |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
75 |
val partial_type_encs = partial_type_enc :: full_type_encs |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
76 |
|
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
77 |
val type_enc_aliases = |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
78 |
[(full_typesN, full_type_encs), |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
79 |
(partial_typesN, partial_type_encs), |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
80 |
(no_typesN, [no_type_enc])] |
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 |
fun unalias_type_enc s = |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
83 |
AList.lookup (op =) type_enc_aliases s |> the_default [s] |
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
84 |
|
54500 | 85 |
val default_metis_lam_trans = combsN |
45519
cd6e78cb6ee8
make metis reconstruction handling more flexible
blanchet
parents:
45511
diff
changeset
|
86 |
|
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
87 |
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
|
88 |
| term_name' _ = "" |
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
89 |
|
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
90 |
fun lambda' v = Term.lambda_name (term_name' v, v) |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
91 |
|
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
49983
diff
changeset
|
92 |
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
|
93 |
fun exists_of v t = HOLogic.exists_const (fastype_of v) $ lambda' v t |
39425 | 94 |
|
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
|
95 |
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
|
96 |
let val ww = "'" ^ w in |
56254 | 97 |
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
|
98 |
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
|
99 |
|
54820 | 100 |
exception ATP_CLASS of string list |
54818 | 101 |
exception ATP_TYPE of string atp_type list |
54811 | 102 |
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
|
103 |
exception ATP_FORMULA of |
54811 | 104 |
(string, string, (string, string atp_type) atp_term, string) atp_formula list |
37991 | 105 |
exception SAME of unit |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
106 |
|
54820 | 107 |
fun class_of_atp_class cls = |
108 |
(case unprefix_and_unascii class_prefix cls of |
|
109 |
SOME s => s |
|
110 |
| NONE => raise ATP_CLASS [cls]) |
|
111 |
||
54811 | 112 |
(* Type variables are given the basic sort "HOL.type". Some will later be constrained by information |
113 |
from type literals, or by type inference. *) |
|
54820 | 114 |
fun typ_of_atp_type ctxt (ty as AType ((a, clss), tys)) = |
54818 | 115 |
let val Ts = map (typ_of_atp_type ctxt) tys in |
54789 | 116 |
(case unprefix_and_unascii type_const_prefix a of |
37991 | 117 |
SOME b => Type (invert_const b, Ts) |
118 |
| NONE => |
|
54818 | 119 |
if not (null tys) then |
120 |
raise ATP_TYPE [ty] (* only "tconst"s have type arguments *) |
|
54789 | 121 |
else |
122 |
(case unprefix_and_unascii tfree_prefix a of |
|
123 |
SOME b => make_tfree ctxt b |
|
124 |
| NONE => |
|
125 |
(* The term could be an Isabelle variable or a variable from the ATP, say "X1" or "_5018". |
|
126 |
Sometimes variables from the ATP are indistinguishable from Isabelle variables, which |
|
127 |
forces us to use a type parameter in all cases. *) |
|
54821 | 128 |
Type_Infer.param 0 ("'" ^ perhaps (unprefix_and_unascii tvar_prefix) a, |
56254 | 129 |
(if null clss then @{sort type} else map class_of_atp_class clss)))) |
37991 | 130 |
end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
131 |
|
54820 | 132 |
fun atp_type_of_atp_term (ATerm ((s, _), us)) = AType ((s, []), map atp_type_of_atp_term us) |
54818 | 133 |
|
134 |
fun typ_of_atp_term ctxt = typ_of_atp_type ctxt o atp_type_of_atp_term |
|
135 |
||
54789 | 136 |
(* 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
|
137 |
fun type_constraint_of_term ctxt (u as ATerm ((a, _), us)) = |
54818 | 138 |
(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
|
139 |
(SOME b, [T]) => (b, T) |
54789 | 140 |
| _ => raise ATP_TERM [u]) |
38014 | 141 |
|
43907
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
142 |
(* Accumulate type constraints in a formula: negative type literals. *) |
38014 | 143 |
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
|
144 |
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
|
145 |
| 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
|
146 |
| add_type_constraint _ _ = I |
38014 | 147 |
|
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
148 |
fun repair_var_name_raw s = |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
149 |
let |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
150 |
fun subscript_name s n = s ^ nat_subscript n |
50704 | 151 |
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
|
152 |
in |
54789 | 153 |
(case space_explode "_" s of |
154 |
[_] => |
|
155 |
(case take_suffix Char.isDigit (String.explode s) of |
|
156 |
(cs1 as _ :: _, cs2 as _ :: _) => |
|
157 |
subscript_name (String.implode cs1) (the (Int.fromString (String.implode cs2))) |
|
158 |
| (_, _) => s) |
|
159 |
| [s1, s2] => (case Int.fromString s2 of SOME n => subscript_name s1 n | NONE => s) |
|
160 |
| _ => s) |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
161 |
end |
43182
649bada59658
slacker version of "fastype_of", in case a function has dummy type
blanchet
parents:
43176
diff
changeset
|
162 |
|
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
163 |
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
|
164 |
(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
|
165 |
SOME s => s |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
166 |
| 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
|
167 |
|
54789 | 168 |
(* The number of type arguments of a constant, zero if it's monomorphic. For (instances of) Skolem |
169 |
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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
else |
073ab5379842
pass type arguments to lambda-lifted Frees, to account for polymorphism
blanchet
parents:
43863
diff
changeset
|
176 |
(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
|
177 |
|
56254 | 178 |
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
|
179 |
|
51192
4dc6bb65c3c3
slacker comparison for Skolems, to avoid trivial equations
blanchet
parents:
50704
diff
changeset
|
180 |
(* 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
|
181 |
fun loose_aconv (Free (s, _), Free (s', _)) = s = s' |
4dc6bb65c3c3
slacker comparison for Skolems, to avoid trivial equations
blanchet
parents:
50704
diff
changeset
|
182 |
| loose_aconv (t, t') = t aconv t' |
4dc6bb65c3c3
slacker comparison for Skolems, to avoid trivial equations
blanchet
parents:
50704
diff
changeset
|
183 |
|
54772 | 184 |
val spass_skolem_prefix = "sk" (* "skc" or "skf" *) |
185 |
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
|
186 |
|
56254 | 187 |
(* First-order translation. No types are known for variables. "Type_Infer.anyT @{sort type}" |
188 |
should allow them to be inferred. *) |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
189 |
fun term_of_atp ctxt textual sym_tab = |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
190 |
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
|
191 |
val thy = Proof_Context.theory_of ctxt |
54789 | 192 |
(* For Metis, we use 1 rather than 0 because variable references in clauses may otherwise |
193 |
conflict with variable constraints in the goal. At least, type inference often fails |
|
194 |
otherwise. See also "axiom_inference" in "Metis_Reconstruct". *) |
|
43094 | 195 |
val var_index = if textual then 0 else 1 |
57199 | 196 |
|
43131
9e9420122f91
fixed interaction between type tags and hAPP in reconstruction code
blanchet
parents:
43130
diff
changeset
|
197 |
fun do_term extra_ts opt_T u = |
54789 | 198 |
(case u of |
54818 | 199 |
ATerm ((s, tys), us) => |
57199 | 200 |
if s = "" then |
201 |
error "Isar proof reconstruction failed because the ATP proof contains unparsable \ |
|
202 |
\material." |
|
51878 | 203 |
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
|
204 |
@{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
|
205 |
else if s = tptp_equal then |
43093 | 206 |
let val ts = map (do_term [] NONE) us in |
54822 | 207 |
if textual andalso length ts = 2 andalso loose_aconv (hd ts, List.last ts) then |
39106 | 208 |
@{const True} |
209 |
else |
|
56254 | 210 |
list_comb (Const (@{const_name HOL.eq}, Type_Infer.anyT @{sort type}), ts) |
39106 | 211 |
end |
54789 | 212 |
else |
213 |
(case unprefix_and_unascii const_prefix s of |
|
214 |
SOME s' => |
|
54818 | 215 |
let val ((s', s''), mangled_us) = s' |> unmangled_const |>> `invert_const in |
54789 | 216 |
if s' = type_tag_name then |
217 |
(case mangled_us @ us of |
|
54818 | 218 |
[typ_u, term_u] => do_term extra_ts (SOME (typ_of_atp_term ctxt typ_u)) term_u |
54789 | 219 |
| _ => raise ATP_TERM us) |
220 |
else if s' = predicator_name then |
|
221 |
do_term [] (SOME @{typ bool}) (hd us) |
|
222 |
else if s' = app_op_name then |
|
223 |
let val extra_t = do_term [] NONE (List.last us) in |
|
224 |
do_term (extra_t :: extra_ts) |
|
57199 | 225 |
(case opt_T of SOME T => SOME (slack_fastype_of extra_t --> T) | NONE => NONE) |
226 |
(nth us (length us - 2)) |
|
54789 | 227 |
end |
228 |
else if s' = type_guard_name then |
|
229 |
@{const True} (* ignore type predicates *) |
|
230 |
else |
|
231 |
let |
|
232 |
val new_skolem = String.isPrefix new_skolem_const_prefix s'' |
|
54818 | 233 |
val num_ty_args = length us - the_default 0 (Symtab.lookup sym_tab s) |
234 |
val (type_us, term_us) = chop num_ty_args us |>> append mangled_us |
|
54789 | 235 |
val term_ts = map (do_term [] NONE) term_us |
54818 | 236 |
|
237 |
val Ts = map (typ_of_atp_type ctxt) tys @ map (typ_of_atp_term ctxt) type_us |
|
54789 | 238 |
val T = |
54818 | 239 |
(if not (null Ts) andalso robust_const_num_type_args thy s' = length Ts then |
57199 | 240 |
if new_skolem then SOME (Type_Infer.paramify_vars (tl Ts ---> hd Ts)) |
241 |
else if textual then try (Sign.const_instance thy) (s', Ts) |
|
242 |
else NONE |
|
54789 | 243 |
else |
244 |
NONE) |
|
245 |
|> (fn SOME T => T |
|
246 |
| NONE => |
|
56254 | 247 |
map slack_fastype_of term_ts ---> |
57199 | 248 |
the_default (Type_Infer.anyT @{sort type}) opt_T) |
54789 | 249 |
val t = |
250 |
if new_skolem then Var ((new_skolem_var_name_of_const s'', var_index), T) |
|
251 |
else Const (unproxify_const s', T) |
|
252 |
in list_comb (t, term_ts @ extra_ts) end |
|
253 |
end |
|
254 |
| NONE => (* a free or schematic variable *) |
|
255 |
let |
|
256 |
(* This assumes that distinct names are mapped to distinct names by |
|
54822 | 257 |
"Variable.variant_frees". This does not hold in general but should hold for |
258 |
ATP-generated Skolem function names, since these end with a digit and |
|
259 |
"variant_frees" appends letters. *) |
|
57199 | 260 |
fun fresh_up s = [(s, ())] |> Variable.variant_frees ctxt [] |> hd |> fst |
261 |
||
54789 | 262 |
val term_ts = |
263 |
map (do_term [] NONE) us |
|
264 |
(* SPASS (3.8ds) and Vampire (2.6) pass arguments to Skolem functions in reverse |
|
265 |
order, which is incompatible with the new Metis skolemizer. *) |
|
266 |
|> exists (fn pre => String.isPrefix pre s) |
|
267 |
[spass_skolem_prefix, vampire_skolem_prefix] ? rev |
|
268 |
val ts = term_ts @ extra_ts |
|
269 |
val T = |
|
270 |
(case opt_T of |
|
271 |
SOME T => map slack_fastype_of term_ts ---> T |
|
54822 | 272 |
| NONE => |
273 |
map slack_fastype_of ts ---> |
|
56254 | 274 |
(case tys of [ty] => typ_of_atp_type ctxt ty | _ => Type_Infer.anyT @{sort type})) |
54789 | 275 |
val t = |
276 |
(case unprefix_and_unascii fixed_var_prefix s of |
|
277 |
SOME s => Free (s, T) |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
278 |
| NONE => |
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
279 |
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
|
280 |
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
|
281 |
else |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
282 |
Var ((repair_var_name textual s, var_index), T)) |
54789 | 283 |
in list_comb (t, ts) end)) |
43093 | 284 |
in do_term [] end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
285 |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
286 |
fun term_of_atom ctxt textual sym_tab pos (u as ATerm ((s, _), _)) = |
38014 | 287 |
if String.isPrefix class_prefix s then |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
288 |
add_type_constraint pos (type_constraint_of_term ctxt u) |
38014 | 289 |
#> pair @{const True} |
290 |
else |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
291 |
pair (term_of_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
|
292 |
|
37991 | 293 |
(* Update schematic type variables with detected sort constraints. It's not |
42563 | 294 |
totally clear whether this code is necessary. *) |
38014 | 295 |
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
|
296 |
let |
37991 | 297 |
fun do_type (Type (a, Ts)) = Type (a, map do_type Ts) |
298 |
| do_type (TVar (xi, s)) = |
|
299 |
TVar (xi, the_default s (Vartab.lookup tvar_tab xi)) |
|
300 |
| do_type (TFree z) = TFree z |
|
301 |
fun do_term (Const (a, T)) = Const (a, do_type T) |
|
302 |
| do_term (Free (a, T)) = Free (a, do_type T) |
|
303 |
| do_term (Var (xi, T)) = Var (xi, do_type T) |
|
304 |
| do_term (t as Bound _) = t |
|
305 |
| do_term (Abs (a, T, t)) = Abs (a, do_type T, do_term t) |
|
306 |
| do_term (t1 $ t2) = do_term t1 $ do_term t2 |
|
307 |
in t |> not (Vartab.is_empty tvar_tab) ? do_term end |
|
308 |
||
39425 | 309 |
fun quantify_over_var quant_of var_s t = |
310 |
let |
|
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
311 |
val vars = filter (fn ((s, _), _) => s = var_s) (Term.add_vars t []) |
52758
7ffcd6f2890d
avoid duplicating Var when the types do not quite fit -- since this step occurs before type inference
blanchet
parents:
52125
diff
changeset
|
312 |
val normTs = vars |> AList.group (op =) |> map (apsnd hd) |
7ffcd6f2890d
avoid duplicating Var when the types do not quite fit -- since this step occurs before type inference
blanchet
parents:
52125
diff
changeset
|
313 |
fun norm_var_types (Var (x, T)) = |
54789 | 314 |
Var (x, (case AList.lookup (op =) normTs x of NONE => T | SOME T' => T')) |
52758
7ffcd6f2890d
avoid duplicating Var when the types do not quite fit -- since this step occurs before type inference
blanchet
parents:
52125
diff
changeset
|
315 |
| norm_var_types t = t |
7ffcd6f2890d
avoid duplicating Var when the types do not quite fit -- since this step occurs before type inference
blanchet
parents:
52125
diff
changeset
|
316 |
in t |> map_aterms norm_var_types |> fold_rev quant_of (map Var normTs) end |
37991 | 317 |
|
54811 | 318 |
(* Interpret an ATP formula as a HOL term, extracting sort constraints as they appear in the |
319 |
formula. *) |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
320 |
fun prop_of_atp ctxt textual sym_tab phi = |
38014 | 321 |
let |
322 |
fun do_formula pos phi = |
|
54789 | 323 |
(case phi of |
38014 | 324 |
AQuant (_, [], phi) => do_formula pos phi |
42526 | 325 |
| AQuant (q, (s, _) :: xs, phi') => |
38014 | 326 |
do_formula pos (AQuant (q, xs, phi')) |
42526 | 327 |
(* FIXME: TFF *) |
54768
ee0881a54c72
fixed confusion between 'prop' and 'bool' introduced in 4960647932ec
blanchet
parents:
54757
diff
changeset
|
328 |
#>> quantify_over_var (case q of AForall => forall_of | AExists => exists_of) |
55185
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
329 |
(repair_var_name textual s) |
38014 | 330 |
| AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not |
37991 | 331 |
| AConn (c, [phi1, phi2]) => |
38014 | 332 |
do_formula (pos |> c = AImplies ? not) phi1 |
333 |
##>> do_formula pos phi2 |
|
334 |
#>> (case c of |
|
54811 | 335 |
AAnd => s_conj |
336 |
| AOr => s_disj |
|
337 |
| AImplies => s_imp |
|
338 |
| AIff => s_iff |
|
339 |
| ANot => raise Fail "impossible connective") |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51878
diff
changeset
|
340 |
| AAtom tm => term_of_atom ctxt textual sym_tab pos tm |
54789 | 341 |
| _ => raise ATP_FORMULA [phi]) |
342 |
in |
|
343 |
repair_tvar_sorts (do_formula true phi Vartab.empty) |
|
344 |
end |
|
37991 | 345 |
|
54500 | 346 |
fun find_first_in_list_vector vec key = |
347 |
Vector.foldl (fn (ps, NONE) => AList.lookup (op =) ps key |
|
348 |
| (_, value) => value) NONE vec |
|
349 |
||
350 |
val unprefix_fact_number = space_implode "_" o tl o space_explode "_" |
|
351 |
||
352 |
fun resolve_one_named_fact fact_names s = |
|
54789 | 353 |
(case try (unprefix fact_prefix) s of |
54500 | 354 |
SOME s' => |
355 |
let val s' = s' |> unprefix_fact_number |> unascii_of in |
|
356 |
s' |> find_first_in_list_vector fact_names |> Option.map (pair s') |
|
357 |
end |
|
54789 | 358 |
| NONE => NONE) |
54506 | 359 |
|
54500 | 360 |
fun resolve_fact fact_names = map_filter (resolve_one_named_fact fact_names) |
361 |
||
362 |
fun resolve_one_named_conjecture s = |
|
54789 | 363 |
(case try (unprefix conjecture_prefix) s of |
54500 | 364 |
SOME s' => Int.fromString s' |
54789 | 365 |
| NONE => NONE) |
54500 | 366 |
|
367 |
val resolve_conjecture = map_filter resolve_one_named_conjecture |
|
368 |
||
369 |
fun is_axiom_used_in_proof pred = |
|
370 |
exists (fn ((_, ss), _, _, _, []) => exists pred ss | _ => false) |
|
371 |
||
372 |
fun add_non_rec_defs fact_names accum = |
|
373 |
Vector.foldl (fn (facts, facts') => |
|
54818 | 374 |
union (op =) (filter (fn (_, (_, status)) => status = Non_Rec_Def) facts) facts') |
54500 | 375 |
accum fact_names |
376 |
||
377 |
val leo2_extcnf_equal_neg_rule = "extcnf_equal_neg" |
|
378 |
val leo2_unfold_def_rule = "unfold_def" |
|
379 |
||
380 |
fun add_fact ctxt fact_names ((_, ss), _, _, rule, deps) = |
|
381 |
(if rule = leo2_extcnf_equal_neg_rule then |
|
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
55285
diff
changeset
|
382 |
insert (op =) (short_thm_name ctxt ext, (Global, General)) |
54500 | 383 |
else if rule = leo2_unfold_def_rule then |
54789 | 384 |
(* LEO 1.3.3 does not record definitions properly, leading to missing dependencies in the TSTP |
385 |
proof. Remove the next line once this is fixed. *) |
|
54500 | 386 |
add_non_rec_defs fact_names |
54788
a898e15b522a
primitive support for SPASS-Pirate (Daniel Wand's polymorphic SPASS prototype)
blanchet
parents:
54774
diff
changeset
|
387 |
else if rule = agsyhol_core_rule orelse rule = satallax_core_rule then |
54500 | 388 |
(fn [] => |
54789 | 389 |
(* agsyHOL and Satallax don't include definitions in their unsatisfiable cores, so we |
390 |
assume the worst and include them all here. *) |
|
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
55285
diff
changeset
|
391 |
[(short_thm_name ctxt ext, (Global, General))] |> add_non_rec_defs fact_names |
54500 | 392 |
| facts => facts) |
393 |
else |
|
394 |
I) |
|
395 |
#> (if null deps then union (op =) (resolve_fact fact_names ss) else I) |
|
396 |
||
397 |
fun used_facts_in_atp_proof ctxt fact_names atp_proof = |
|
398 |
if null atp_proof then Vector.foldl (uncurry (union (op =))) [] fact_names |
|
399 |
else fold (add_fact ctxt fact_names) atp_proof [] |
|
400 |
||
401 |
fun used_facts_in_unsound_atp_proof _ _ [] = NONE |
|
402 |
| used_facts_in_unsound_atp_proof ctxt fact_names atp_proof = |
|
403 |
let val used_facts = used_facts_in_atp_proof ctxt fact_names atp_proof in |
|
404 |
if forall (fn (_, (sc, _)) => sc = Global) used_facts andalso |
|
54506 | 405 |
not (is_axiom_used_in_proof (not o null o resolve_conjecture o single) atp_proof) then |
54500 | 406 |
SOME (map fst used_facts) |
407 |
else |
|
408 |
NONE |
|
409 |
end |
|
410 |
||
411 |
val ascii_of_lam_fact_prefix = ascii_of lam_fact_prefix |
|
412 |
||
413 |
(* overapproximation (good enough) *) |
|
414 |
fun is_lam_lifted s = |
|
415 |
String.isPrefix fact_prefix s andalso |
|
416 |
String.isSubstring ascii_of_lam_fact_prefix s |
|
417 |
||
418 |
val is_combinator_def = String.isPrefix (helper_prefix ^ combinator_prefix) |
|
419 |
||
55257 | 420 |
fun atp_proof_prefers_lifting atp_proof = |
421 |
(is_axiom_used_in_proof is_combinator_def atp_proof, |
|
422 |
is_axiom_used_in_proof is_lam_lifted atp_proof) = (false, true) |
|
54500 | 423 |
|
424 |
val is_typed_helper_name = |
|
425 |
String.isPrefix helper_prefix andf String.isSuffix typed_helper_suffix |
|
426 |
||
427 |
fun is_typed_helper_used_in_atp_proof atp_proof = |
|
428 |
is_axiom_used_in_proof is_typed_helper_name atp_proof |
|
429 |
||
54772 | 430 |
fun replace_one_dependency (old, new) dep = if is_same_atp_step dep old then new else [dep] |
431 |
fun replace_dependencies_in_line old_new (name, role, t, rule, deps) = |
|
432 |
(name, role, t, rule, fold (union (op =) o replace_one_dependency old_new) deps []) |
|
433 |
||
54499 | 434 |
fun repair_name "$true" = "c_True" |
435 |
| repair_name "$false" = "c_False" |
|
436 |
| repair_name "$$e" = tptp_equal (* seen in Vampire proofs *) |
|
437 |
| repair_name s = |
|
438 |
if is_tptp_equal s orelse |
|
439 |
(* seen in Vampire proofs *) |
|
440 |
(String.isPrefix "sQ" s andalso String.isSuffix "_eqProxy" s) then |
|
441 |
tptp_equal |
|
442 |
else |
|
443 |
s |
|
444 |
||
445 |
fun infer_formula_types ctxt = |
|
446 |
Type.constraint HOLogic.boolT |
|
54756 | 447 |
#> Syntax.check_term (Proof_Context.set_mode Proof_Context.mode_schematic ctxt) |
54499 | 448 |
|
449 |
val combinator_table = |
|
450 |
[(@{const_name Meson.COMBI}, @{thm Meson.COMBI_def [abs_def]}), |
|
451 |
(@{const_name Meson.COMBK}, @{thm Meson.COMBK_def [abs_def]}), |
|
452 |
(@{const_name Meson.COMBB}, @{thm Meson.COMBB_def [abs_def]}), |
|
453 |
(@{const_name Meson.COMBC}, @{thm Meson.COMBC_def [abs_def]}), |
|
454 |
(@{const_name Meson.COMBS}, @{thm Meson.COMBS_def [abs_def]})] |
|
455 |
||
456 |
fun uncombine_term thy = |
|
457 |
let |
|
458 |
fun aux (t1 $ t2) = betapply (pairself aux (t1, t2)) |
|
459 |
| aux (Abs (s, T, t')) = Abs (s, T, aux t') |
|
460 |
| aux (t as Const (x as (s, _))) = |
|
461 |
(case AList.lookup (op =) combinator_table s of |
|
54756 | 462 |
SOME thm => thm |> prop_of |> specialize_type thy x |> Logic.dest_equals |> snd |
463 |
| NONE => t) |
|
54499 | 464 |
| aux t = t |
465 |
in aux end |
|
466 |
||
467 |
fun unlift_term lifted = |
|
468 |
map_aterms (fn t as Const (s, _) => |
|
469 |
if String.isPrefix lam_lifted_prefix s then |
|
54756 | 470 |
(* FIXME: do something about the types *) |
471 |
(case AList.lookup (op =) lifted s of |
|
472 |
SOME t => unlift_term lifted t |
|
473 |
| NONE => t) |
|
54499 | 474 |
else |
475 |
t |
|
476 |
| t => t) |
|
477 |
||
54756 | 478 |
fun termify_line ctxt lifted sym_tab (name, role, u, rule, deps) = |
54499 | 479 |
let |
480 |
val thy = Proof_Context.theory_of ctxt |
|
54756 | 481 |
val t = u |
482 |
|> prop_of_atp ctxt true sym_tab |
|
483 |
|> uncombine_term thy |
|
484 |
|> unlift_term lifted |
|
485 |
|> infer_formula_types ctxt |
|
54757
4960647932ec
use 'prop' rather than 'bool' systematically in Isar reconstruction code
blanchet
parents:
54756
diff
changeset
|
486 |
|> HOLogic.mk_Trueprop |
54756 | 487 |
in |
488 |
(name, role, t, rule, deps) |
|
489 |
end |
|
54499 | 490 |
|
491 |
val waldmeister_conjecture_num = "1.0.0.0" |
|
492 |
||
54756 | 493 |
fun repair_waldmeister_endgame proof = |
54499 | 494 |
let |
56854 | 495 |
fun repair_tail (name, _, @{const Trueprop} $ t, rule, deps) = |
496 |
(name, Negated_Conjecture, @{const Trueprop} $ s_not t, rule, deps) |
|
54756 | 497 |
fun repair_body [] = [] |
498 |
| repair_body ((line as ((num, _), _, _, _, _)) :: lines) = |
|
499 |
if num = waldmeister_conjecture_num then map repair_tail (line :: lines) |
|
500 |
else line :: repair_body lines |
|
501 |
in |
|
502 |
repair_body proof |
|
503 |
end |
|
54499 | 504 |
|
505 |
fun termify_atp_proof ctxt pool lifted sym_tab = |
|
506 |
clean_up_atp_proof_dependencies |
|
507 |
#> nasty_atp_proof pool |
|
508 |
#> map_term_names_in_atp_proof repair_name |
|
54756 | 509 |
#> map (termify_line ctxt lifted sym_tab) |
54499 | 510 |
#> repair_waldmeister_endgame |
511 |
||
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
512 |
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
|
513 |
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
|
514 |
| 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
|
515 |
|
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
516 |
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
|
517 |
let |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
518 |
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
|
519 |
|
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
520 |
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
|
521 |
| 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
|
522 |
| 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
|
523 |
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
|
524 |
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
|
525 |
(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
|
526 |
end |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
527 |
else |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
528 |
I |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
529 |
| 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
|
530 |
|
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
531 |
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
|
532 |
val num_alls = length alls |
55195 | 533 |
|
534 |
fun fix_skos args (t $ u) = fix_skos (fix_skos [] u :: args) t |
|
535 |
| fix_skos args (t as Free (s, T)) = |
|
536 |
if is_sko s then list_comb (Free (s, funpow num_alls body_type T), drop num_alls args) |
|
537 |
else list_comb (t, args) |
|
538 |
| fix_skos [] (Abs (s, T, t)) = Abs (s, T, fix_skos [] t) |
|
539 |
| fix_skos [] t = t |
|
540 |
| fix_skos args t = list_comb (fix_skos [] t, args) |
|
541 |
||
542 |
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
|
543 |
|
55195 | 544 |
fun add_sko (t as Free (s, _)) = is_sko s ? insert (op aconv) t |
545 |
| 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
|
546 |
|
55195 | 547 |
val exs = Term.fold_aterms add_sko t' [] |
548 |
in |
|
549 |
t' |
|
550 |
|> HOLogic.dest_Trueprop |
|
551 |
|> fold exists_of exs |> Term.map_abs_vars (K Name.uu) |
|
552 |
|> fold_rev forall_of alls |
|
553 |
|> 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
|
554 |
end |
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
555 |
|
54772 | 556 |
fun introduce_spass_skolem [] = [] |
557 |
| introduce_spass_skolem (proof as (_, _, _, rule1, _) :: _) = |
|
558 |
if rule1 = spass_input_rule then |
|
559 |
let |
|
560 |
fun add_sko (Free (s, _)) = String.isPrefix spass_skolem_prefix s ? insert (op =) s |
|
561 |
| add_sko _ = I |
|
562 |
||
563 |
(* union-find would be faster *) |
|
54799 | 564 |
fun add_cycle [] = I |
565 |
| add_cycle ss = |
|
54772 | 566 |
fold (fn s => Graph.default_node (s, ())) ss |
567 |
#> fold Graph.add_edge (ss ~~ tl ss @ [hd ss]) |
|
568 |
||
569 |
val (input_steps, other_steps) = List.partition (null o #5) proof |
|
570 |
||
571 |
val skoss = map (fn (_, _, t, _, _) => Term.fold_aterms add_sko t []) input_steps |
|
572 |
val skoss_input_steps = filter_out (null o fst) (skoss ~~ input_steps) |
|
54799 | 573 |
val groups = Graph.strong_conn (fold add_cycle skoss Graph.empty) |
54772 | 574 |
|
575 |
fun step_name_of_group skos = (implode skos, []) |
|
576 |
fun in_group group = member (op =) group o hd |
|
577 |
fun group_of sko = the (find_first (fn group => in_group group sko) groups) |
|
578 |
||
55192
b75b52c7cf94
unskolemize SPASS formula to ensure that the variables are in the right order for 'metis's skolemizer
blanchet
parents:
55185
diff
changeset
|
579 |
fun new_steps (skoss_steps : (string list * (term, 'a) atp_step) list) group = |
54772 | 580 |
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
|
581 |
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
|
582 |
val name0 = name |>> prefix "0" |
54772 | 583 |
val t = |
584 |
skoss_steps |
|
585 |
|> map (snd #> #3 #> HOLogic.dest_Trueprop) |
|
586 |
|> Library.foldr1 s_conj |
|
587 |
|> 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
|
588 |
val skos = fold (union (op =) o fst) skoss_steps [] |
54772 | 589 |
val deps = map (snd #> #1) skoss_steps |
590 |
in |
|
55195 | 591 |
[(name0, Unknown, unskolemize_term skos t, spass_pre_skolemize_rule, deps), |
592 |
(name, Unknown, t, spass_skolemize_rule, [name0])] |
|
54772 | 593 |
end |
594 |
||
595 |
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
|
596 |
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
|
597 |
groups |
54772 | 598 |
|
599 |
val old_news = |
|
600 |
map (fn (skos, (name, _, _, _, _)) => (name, [step_name_of_group (group_of skos)])) |
|
601 |
skoss_input_steps |
|
602 |
val repair_deps = fold replace_dependencies_in_line old_news |
|
603 |
in |
|
604 |
input_steps @ sko_steps @ map repair_deps other_steps |
|
605 |
end |
|
606 |
else |
|
607 |
proof |
|
608 |
||
54505 | 609 |
fun factify_atp_proof fact_names hyp_ts concl_t atp_proof = |
610 |
let |
|
54799 | 611 |
fun factify_step ((num, ss), _, t, rule, deps) = |
54505 | 612 |
let |
613 |
val (ss', role', t') = |
|
614 |
(case resolve_conjecture ss of |
|
615 |
[j] => |
|
616 |
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
|
617 |
| _ => |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
618 |
(case resolve_fact fact_names ss of |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
619 |
[] => (ss, Plain, t) |
a0bd8d6414e6
centralized & repaired handling of bound variables in intermediate data structure (viva de Bruijn)
blanchet
parents:
54822
diff
changeset
|
620 |
| facts => (map fst facts, Axiom, t))) |
54505 | 621 |
in |
622 |
((num, ss'), role', t', rule, deps) |
|
623 |
end |
|
624 |
||
625 |
val atp_proof = map factify_step atp_proof |
|
626 |
val names = map #1 atp_proof |
|
627 |
||
628 |
fun repair_dep (num, ss) = (num, the_default ss (AList.lookup (op =) names num)) |
|
629 |
fun repair_deps (name, role, t, rule, deps) = (name, role, t, rule, map repair_dep deps) |
|
54772 | 630 |
in |
631 |
map repair_deps atp_proof |
|
632 |
end |
|
54505 | 633 |
|
31038 | 634 |
end; |