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