55596
|
1 |
(* Title: HOL/TPTP/TPTP_Parser/tptp_reconstruct.ML
|
|
2 |
Author: Nik Sultana, Cambridge University Computer Laboratory
|
|
3 |
|
|
4 |
Reconstructs TPTP proofs in Isabelle/HOL.
|
|
5 |
Specialised to work with proofs produced by LEO-II.
|
|
6 |
|
|
7 |
TODO
|
|
8 |
- Proof transformation to remove "copy" steps, and perhaps other dud inferences.
|
|
9 |
*)
|
|
10 |
|
|
11 |
signature TPTP_RECONSTRUCT =
|
|
12 |
sig
|
|
13 |
(* Interface used by TPTP_Reconstruct.thy, to define LEO-II proof reconstruction. *)
|
|
14 |
|
|
15 |
datatype formula_kind =
|
|
16 |
Conjunctive of bool option
|
|
17 |
| Disjunctive of bool option
|
|
18 |
| Biimplicational of bool option
|
|
19 |
| Negative of bool option
|
|
20 |
| Existential of bool option * typ
|
|
21 |
| Universal of bool option * typ
|
|
22 |
| Equational of bool option * typ
|
|
23 |
| Atomic of bool option
|
|
24 |
| Implicational of bool option
|
|
25 |
type formula_meaning =
|
|
26 |
(string *
|
|
27 |
{role : TPTP_Syntax.role,
|
|
28 |
fmla : term,
|
|
29 |
source_inf_opt : TPTP_Proof.source_info option})
|
|
30 |
type proof_annotation =
|
|
31 |
{problem_name : TPTP_Problem_Name.problem_name,
|
|
32 |
skolem_defs : ((*skolem const name*)string * Binding.binding) list,
|
|
33 |
defs : ((*node name*)string * Binding.binding) list,
|
|
34 |
axs : ((*node name*)string * Binding.binding) list,
|
|
35 |
(*info for each node (for all lines in the TPTP proof)*)
|
|
36 |
meta : formula_meaning list}
|
|
37 |
type rule_info =
|
|
38 |
{inference_name : string, (*name of calculus rule*)
|
|
39 |
inference_fmla : term, (*the inference as a term*)
|
|
40 |
parents : string list}
|
|
41 |
|
|
42 |
exception UNPOLARISED of term
|
|
43 |
|
|
44 |
val remove_polarity : bool -> term -> term * bool
|
|
45 |
val interpret_bindings :
|
|
46 |
TPTP_Problem_Name.problem_name -> theory -> TPTP_Proof.parent_detail list -> (string * term) list -> (string * term) list
|
|
47 |
val diff_and_instantiate : Proof.context -> thm -> term -> term -> thm (*FIXME from library*)
|
|
48 |
val strip_top_all_vars : (string * typ) list -> term -> (string * typ) list * term
|
|
49 |
val strip_top_All_vars : term -> (string * typ) list * term
|
|
50 |
val strip_top_All_var : term -> (string * typ) * term
|
|
51 |
val new_consts_between : term -> term -> term list
|
|
52 |
val get_pannot_of_prob : theory -> TPTP_Problem_Name.problem_name -> proof_annotation
|
|
53 |
val inference_at_node : 'a -> TPTP_Problem_Name.problem_name -> formula_meaning list -> string -> rule_info option
|
|
54 |
val node_info : (string * 'a) list -> ('a -> 'b) -> string -> 'b
|
|
55 |
|
|
56 |
type step_id = string
|
|
57 |
datatype rolling_stock =
|
|
58 |
Step of step_id
|
|
59 |
| Assumed
|
|
60 |
| Unconjoin
|
|
61 |
| Split of step_id (*where split occurs*) *
|
|
62 |
step_id (*where split ends*) *
|
|
63 |
step_id list (*children of the split*)
|
|
64 |
| Synth_step of step_id (*A step which doesn't necessarily appear in
|
|
65 |
the original proof, or which has been modified slightly for better
|
|
66 |
handling by Isabelle*)
|
|
67 |
| Annotated_step of step_id * string (*Same interpretation as
|
|
68 |
"Step", except that additional information is attached. This is
|
|
69 |
currently used for debugging: Steps are mapped to Annotated_steps
|
|
70 |
and their rule names are included as strings*)
|
|
71 |
| Definition of step_id (*Mirrors TPTP role*)
|
|
72 |
| Axiom of step_id (*Mirrors TPTP role*)
|
|
73 |
| Caboose
|
|
74 |
|
|
75 |
|
|
76 |
(* Interface for using the proof reconstruction. *)
|
|
77 |
|
|
78 |
val import_thm : bool -> Path.T list -> Path.T -> (proof_annotation -> theory -> proof_annotation * theory) -> theory -> theory
|
|
79 |
val get_fmlas_of_prob : theory -> TPTP_Problem_Name.problem_name -> TPTP_Interpret.tptp_formula_meaning list
|
|
80 |
val structure_fmla_meaning : 'a * 'b * 'c * 'd -> 'a * {fmla: 'c, role: 'b, source_inf_opt: 'd}
|
|
81 |
val make_skeleton : Proof.context -> proof_annotation -> rolling_stock list
|
|
82 |
val naive_reconstruct_tacs :
|
|
83 |
(Proof.context -> TPTP_Problem_Name.problem_name -> step_id -> thm) ->
|
|
84 |
TPTP_Problem_Name.problem_name -> Proof.context -> (rolling_stock * term option * (thm * tactic) option) list
|
|
85 |
val naive_reconstruct_tac :
|
|
86 |
Proof.context -> (Proof.context -> TPTP_Problem_Name.problem_name -> step_id -> thm) -> TPTP_Problem_Name.problem_name -> tactic
|
|
87 |
val reconstruct : Proof.context -> (TPTP_Problem_Name.problem_name -> tactic) -> TPTP_Problem_Name.problem_name -> thm
|
|
88 |
end
|
|
89 |
|
|
90 |
structure TPTP_Reconstruct : TPTP_RECONSTRUCT =
|
|
91 |
struct
|
|
92 |
|
|
93 |
open TPTP_Reconstruct_Library
|
|
94 |
open TPTP_Syntax
|
|
95 |
|
|
96 |
(*FIXME move to more general struct*)
|
|
97 |
(*Extract the formulas of an imported TPTP problem -- these formulas
|
|
98 |
may make up a proof*)
|
|
99 |
fun get_fmlas_of_prob thy prob_name : TPTP_Interpret.tptp_formula_meaning list =
|
|
100 |
AList.lookup (op =) (TPTP_Interpret.get_manifests thy) prob_name
|
|
101 |
|> the |> #3 (*get formulas*);
|
|
102 |
|
|
103 |
|
|
104 |
(** General **)
|
|
105 |
|
|
106 |
(* Proof annotations *)
|
|
107 |
|
|
108 |
(*FIXME modify TPTP_Interpret.tptp_formula_meaning into this type*)
|
|
109 |
type formula_meaning =
|
|
110 |
(string *
|
|
111 |
{role : TPTP_Syntax.role,
|
|
112 |
fmla : term,
|
|
113 |
source_inf_opt : TPTP_Proof.source_info option})
|
|
114 |
|
|
115 |
fun apply_to_parent_info f
|
|
116 |
(n, {role, fmla, source_inf_opt}) =
|
|
117 |
let
|
|
118 |
val source_inf_opt' =
|
|
119 |
case source_inf_opt of
|
|
120 |
NONE => NONE
|
|
121 |
| SOME (TPTP_Proof.Inference (inf_name, sinfos, pinfos)) =>
|
|
122 |
SOME (TPTP_Proof.Inference (inf_name, sinfos, f pinfos))
|
|
123 |
in
|
|
124 |
(n, {role = role, fmla = fmla, source_inf_opt = source_inf_opt'})
|
|
125 |
end
|
|
126 |
|
|
127 |
fun structure_fmla_meaning (s, r, t, info) =
|
|
128 |
(s, {role = r, fmla = t, source_inf_opt = info})
|
|
129 |
|
|
130 |
type proof_annotation =
|
|
131 |
{problem_name : TPTP_Problem_Name.problem_name,
|
|
132 |
skolem_defs : ((*skolem const name*)string * Binding.binding) list,
|
|
133 |
defs : ((*node name*)string * Binding.binding) list,
|
|
134 |
axs : ((*node name*)string * Binding.binding) list,
|
|
135 |
(*info for each node (for all lines in the TPTP proof)*)
|
|
136 |
meta : formula_meaning list}
|
|
137 |
|
|
138 |
fun empty_pannot prob_name =
|
|
139 |
{problem_name = prob_name,
|
|
140 |
skolem_defs = [],
|
|
141 |
defs = [],
|
|
142 |
axs = [],
|
|
143 |
meta = []}
|
|
144 |
|
|
145 |
|
|
146 |
(* Storage of proof data *)
|
|
147 |
|
|
148 |
exception MANIFEST of TPTP_Problem_Name.problem_name * string (*FIXME move to TPTP_Interpret?*)
|
|
149 |
|
|
150 |
type manifest = TPTP_Problem_Name.problem_name * proof_annotation
|
|
151 |
|
|
152 |
(*manifest equality simply depends on problem name*)
|
|
153 |
fun manifest_eq ((prob_name1, _), (prob_name2, _)) = prob_name1 = prob_name2
|
|
154 |
|
|
155 |
structure TPTP_Reconstruction_Data = Theory_Data
|
|
156 |
(
|
|
157 |
type T = manifest list
|
|
158 |
val empty = []
|
|
159 |
val extend = I
|
|
160 |
fun merge data : T = Library.merge manifest_eq data
|
|
161 |
)
|
|
162 |
val get_manifests : theory -> manifest list = TPTP_Reconstruction_Data.get
|
|
163 |
|
|
164 |
fun update_manifest prob_name pannot thy =
|
|
165 |
let
|
|
166 |
val idx =
|
|
167 |
find_index
|
|
168 |
(fn (n, _) => n = prob_name)
|
|
169 |
(get_manifests thy)
|
|
170 |
val transf = (fn _ =>
|
|
171 |
(prob_name, pannot))
|
|
172 |
in
|
|
173 |
TPTP_Reconstruction_Data.map
|
|
174 |
(nth_map idx transf)
|
|
175 |
thy
|
|
176 |
end
|
|
177 |
|
|
178 |
(*similar to get_fmlas_of_prob but for proofs*)
|
|
179 |
fun get_pannot_of_prob thy prob_name : proof_annotation =
|
|
180 |
case AList.lookup (op =) (get_manifests thy) prob_name of
|
|
181 |
SOME pa => pa
|
|
182 |
| NONE => raise (MANIFEST (prob_name, "Could not find proof annotation"))
|
|
183 |
|
|
184 |
|
|
185 |
(* Constants *)
|
|
186 |
|
|
187 |
(*Prefix used for naming inferences which were added during proof
|
|
188 |
transformation. (e.g., this is used to name "bind"-inference nodes
|
|
189 |
described below)*)
|
|
190 |
val inode_prefixK = "inode"
|
|
191 |
|
|
192 |
(*New inference rule name, which is added to indicate that some
|
|
193 |
variable has been instantiated. Additional proof metadata will
|
|
194 |
indicate which variable, and how it was instantiated*)
|
|
195 |
val bindK = "bind"
|
|
196 |
|
|
197 |
(*New inference rule name, which is added to indicate that some
|
|
198 |
(validity-preserving) preprocessing has been done to a (singleton)
|
|
199 |
clause prior to it being split.*)
|
|
200 |
val split_preprocessingK = "split_preprocessing"
|
|
201 |
|
|
202 |
|
|
203 |
(* Storage of internal values *)
|
|
204 |
|
|
205 |
type tptp_reconstruction_state = {next_int : int}
|
|
206 |
structure TPTP_Reconstruction_Internal_Data = Theory_Data
|
|
207 |
(
|
|
208 |
type T = tptp_reconstruction_state
|
|
209 |
val empty = {next_int = 0}
|
|
210 |
val extend = I
|
|
211 |
fun merge data : T = snd data
|
|
212 |
)
|
|
213 |
|
|
214 |
(*increment internal counter, and obtain the current next value*)
|
|
215 |
fun get_next_int thy : int * theory =
|
|
216 |
let
|
|
217 |
val state = TPTP_Reconstruction_Internal_Data.get thy
|
|
218 |
val state' = {next_int = 1 + #next_int state}
|
|
219 |
in
|
|
220 |
(#next_int state,
|
|
221 |
TPTP_Reconstruction_Internal_Data.put state' thy)
|
|
222 |
end
|
|
223 |
|
|
224 |
(*FIXME in some applications (e.g. where the name is used for an
|
|
225 |
inference node) need to check that the name is fresh, to avoid
|
|
226 |
collisions with other bits of the proof*)
|
|
227 |
val get_next_name =
|
|
228 |
get_next_int
|
|
229 |
#> apfst (fn i => inode_prefixK ^ Int.toString i)
|
|
230 |
|
|
231 |
|
|
232 |
(* Building the index *)
|
|
233 |
|
|
234 |
(*thrown when we're expecting a TPTP_Proof.Bind annotation but find something else*)
|
|
235 |
exception NON_BINDING
|
|
236 |
(*given a list of pairs consisting of a variable name and
|
|
237 |
TPTP formula, returns the list consisting of the original
|
|
238 |
variable name and the interpreted HOL formula. Needs the
|
|
239 |
problem name to ensure use of correct interpretations for
|
|
240 |
constants and types.*)
|
|
241 |
fun interpret_bindings (prob_name : TPTP_Problem_Name.problem_name) thy bindings acc =
|
|
242 |
if null bindings then acc
|
|
243 |
else
|
|
244 |
case hd bindings of
|
|
245 |
TPTP_Proof.Bind (v, fmla) =>
|
|
246 |
let
|
|
247 |
val (type_map, const_map) =
|
|
248 |
case AList.lookup (op =) (TPTP_Interpret.get_manifests thy) prob_name of
|
|
249 |
NONE => raise (MANIFEST (prob_name, "Problem details not found in interpretation manifest"))
|
|
250 |
| SOME (type_map, const_map, _) => (type_map, const_map)
|
|
251 |
|
|
252 |
(*FIXME get config from the envir or make it parameter*)
|
|
253 |
val config =
|
|
254 |
{cautious = true,
|
|
255 |
problem_name = SOME prob_name}
|
|
256 |
val result =
|
|
257 |
(v,
|
|
258 |
TPTP_Interpret.interpret_formula
|
|
259 |
config TPTP_Syntax.THF
|
|
260 |
const_map [] type_map fmla thy
|
|
261 |
|> fst)
|
|
262 |
in
|
|
263 |
interpret_bindings prob_name thy (tl bindings) (result :: acc)
|
|
264 |
end
|
|
265 |
| _ => raise NON_BINDING
|
|
266 |
|
|
267 |
type rule_info =
|
|
268 |
{inference_name : string, (*name of calculus rule*)
|
|
269 |
inference_fmla : term, (*the inference as a term*)
|
|
270 |
parents : string list}
|
|
271 |
|
|
272 |
(*Instantiates a binding in orig_parent_fmla. Used in a proof
|
|
273 |
transformation to factor out instantiations from inferences.*)
|
|
274 |
fun apply_binding thy prob_name orig_parent_fmla target_fmla bindings =
|
|
275 |
let
|
|
276 |
val bindings' = interpret_bindings prob_name thy bindings []
|
|
277 |
|
|
278 |
(*capture selected free variables. these variables, and their
|
|
279 |
intended de Bruijn index, are included in "var_ctxt"*)
|
|
280 |
fun bind_free_vars var_ctxt t =
|
|
281 |
case t of
|
|
282 |
Const _ => t
|
|
283 |
| Var _ => t
|
|
284 |
| Bound _ => t
|
|
285 |
| Abs (x, ty, t') => Abs (x, ty, bind_free_vars (x :: var_ctxt) t')
|
|
286 |
| Free (x, ty) =>
|
|
287 |
let
|
|
288 |
val idx = find_index (fn y => y = x) var_ctxt
|
|
289 |
in
|
|
290 |
if idx > ~1 andalso
|
|
291 |
ty = dummyT (*this check not really needed*) then
|
|
292 |
Bound idx
|
|
293 |
else t
|
|
294 |
end
|
|
295 |
| t1 $ t2 => bind_free_vars var_ctxt t1 $ bind_free_vars var_ctxt t2
|
|
296 |
|
|
297 |
(*Instantiate specific quantified variables:
|
|
298 |
Look for subterms of form (! (% x. M)) where "x" appears as a "bound_var",
|
|
299 |
then replace "x" for "body" in "M".
|
|
300 |
Should only be applied at formula top level -- i.e., once past the quantifier
|
|
301 |
prefix we needn't bother with looking for bound_vars.
|
|
302 |
"var"_ctxt is used to keep track of lambda-bindings we encounter, to capture
|
|
303 |
free variables in "body" correctly (i.e., replace Free with Bound having the
|
|
304 |
right index)*)
|
|
305 |
fun instantiate_bound (binding as (bound_var, body)) (initial as (var_ctxt, t)) =
|
|
306 |
case t of
|
|
307 |
Const _ => initial
|
|
308 |
| Free _ => initial
|
|
309 |
| Var _ => initial
|
|
310 |
| Bound _ => initial
|
|
311 |
| Abs _ => initial
|
|
312 |
| t1 $ (t2 as Abs (x, ty, t')) =>
|
|
313 |
if is_Const t1 then
|
|
314 |
(*Could be fooled by shadowing, but if order matters
|
|
315 |
then should still be able to handle formulas like
|
|
316 |
(! X, X. F).*)
|
|
317 |
if x = bound_var andalso
|
|
318 |
fst (dest_Const t1) = @{const_name All} then
|
|
319 |
(*Body might contain free variables, so bind them using "var_ctxt".
|
|
320 |
this involves replacing instances of Free with instances of Bound
|
|
321 |
at the right index.*)
|
|
322 |
let val body' = bind_free_vars var_ctxt body
|
|
323 |
in
|
|
324 |
(var_ctxt,
|
|
325 |
betapply (t2, body'))
|
|
326 |
end
|
|
327 |
else
|
|
328 |
let
|
|
329 |
val (var_ctxt', rest) = instantiate_bound binding (x :: var_ctxt, t')
|
|
330 |
in
|
|
331 |
(var_ctxt',
|
|
332 |
t1 $ Abs (x, ty, rest))
|
|
333 |
end
|
|
334 |
else initial
|
|
335 |
| t1 $ t2 =>
|
|
336 |
let
|
|
337 |
val (var_ctxt', rest) = instantiate_bound binding (var_ctxt, t2)
|
|
338 |
in
|
|
339 |
(var_ctxt', t1 $ rest)
|
|
340 |
end
|
|
341 |
|
|
342 |
(*Here we preempt the following problem:
|
|
343 |
if have (! X1, X2, X3. body), and X1 is instantiated to
|
|
344 |
"c X2 X3", then the current code will yield
|
|
345 |
(! X2, X3, X2a, X3a. body').
|
|
346 |
To avoid this, we must first push X1 in, before calling
|
|
347 |
instantiate_bound, to make sure that bound variables don't
|
|
348 |
get free.*)
|
|
349 |
fun safe_instantiate_bound (binding as (bound_var, body)) (var_ctxt, t) =
|
|
350 |
instantiate_bound binding
|
|
351 |
(var_ctxt, push_allvar_in bound_var t)
|
|
352 |
|
|
353 |
(*return true if one of the types is polymorphic*)
|
|
354 |
fun is_polymorphic tys =
|
|
355 |
if null tys then false
|
|
356 |
else
|
|
357 |
case hd tys of
|
|
358 |
Type (_, tys') => is_polymorphic (tl tys @ tys')
|
|
359 |
| TFree _ => true
|
|
360 |
| TVar _ => true
|
|
361 |
|
|
362 |
(*find the type of a quantified variable, at the "topmost" binding
|
|
363 |
occurrence*)
|
|
364 |
local
|
|
365 |
fun type_of_quantified_var' s ts =
|
|
366 |
if null ts then NONE
|
|
367 |
else
|
|
368 |
case hd ts of
|
|
369 |
Const _ => type_of_quantified_var' s (tl ts)
|
|
370 |
| Free _ => type_of_quantified_var' s (tl ts)
|
|
371 |
| Var _ => type_of_quantified_var' s (tl ts)
|
|
372 |
| Bound _ => type_of_quantified_var' s (tl ts)
|
|
373 |
| Abs (s', ty, t') =>
|
|
374 |
if s = s' then SOME ty
|
|
375 |
else type_of_quantified_var' s (t' :: tl ts)
|
|
376 |
| t1 $ t2 => type_of_quantified_var' s (t1 :: t2 :: tl ts)
|
|
377 |
in
|
|
378 |
fun type_of_quantified_var s =
|
|
379 |
single #> type_of_quantified_var' s
|
|
380 |
end
|
|
381 |
|
|
382 |
(*Form the universal closure of "t".
|
|
383 |
NOTE remark above "val frees" about ordering of quantified variables*)
|
|
384 |
fun close_formula t =
|
|
385 |
let
|
|
386 |
(*The ordering of Frees in this list affects the order in which variables appear
|
|
387 |
in the quantification prefix. Currently this is assumed not to matter.
|
|
388 |
This consists of a list of pairs: the first element consists of the "original"
|
|
389 |
free variable, and the latter consists of the monomorphised equivalent. The
|
|
390 |
two elements are identical if the original is already monomorphic.
|
|
391 |
This monomorphisation is needed since, owing to TPTP's lack of type annotations,
|
|
392 |
variables might not be constrained by type info. This results in them being
|
|
393 |
interpreted as polymorphic. E.g., this issue comes up in CSR148^1*)
|
|
394 |
val frees_monomorphised =
|
|
395 |
fold_aterms
|
|
396 |
(fn t => fn rest =>
|
|
397 |
if is_Free t then
|
|
398 |
let
|
|
399 |
val (s, ty) = dest_Free t
|
|
400 |
val ty' =
|
|
401 |
if ty = dummyT orelse is_polymorphic [ty] then
|
|
402 |
the (type_of_quantified_var s target_fmla)
|
|
403 |
else ty
|
|
404 |
in insert (op =) (t, Free (s, ty')) rest
|
|
405 |
end
|
|
406 |
else rest)
|
|
407 |
t []
|
|
408 |
in
|
|
409 |
Term.subst_free frees_monomorphised t
|
|
410 |
|> fold (fn (s, ty) => fn t =>
|
|
411 |
HOLogic.mk_all (s, ty, t))
|
|
412 |
(map (snd #> dest_Free) frees_monomorphised)
|
|
413 |
end
|
|
414 |
|
|
415 |
(*FIXME currently assuming that we're only ever given a single binding each time this is called*)
|
|
416 |
val _ = @{assert} (length bindings' = 1)
|
|
417 |
|
|
418 |
in
|
|
419 |
fold safe_instantiate_bound bindings' ([], HOLogic.dest_Trueprop orig_parent_fmla)
|
|
420 |
|> snd (*discard var typing context*)
|
|
421 |
|> close_formula
|
|
422 |
|> single
|
|
423 |
|> Type_Infer_Context.infer_types (Context.proof_of (Context.Theory thy))
|
|
424 |
|> the_single
|
|
425 |
|> HOLogic.mk_Trueprop
|
|
426 |
|> rpair bindings'
|
|
427 |
end
|
|
428 |
|
|
429 |
exception RECONSTRUCT of string
|
|
430 |
|
|
431 |
(*Some of these may be redundant wrt the original aims of this
|
|
432 |
datatype, but it's useful to have a datatype to classify formulas
|
|
433 |
for use by other functions as well.*)
|
|
434 |
datatype formula_kind =
|
|
435 |
Conjunctive of bool option
|
|
436 |
| Disjunctive of bool option
|
|
437 |
| Biimplicational of bool option
|
|
438 |
| Negative of bool option
|
|
439 |
| Existential of bool option * typ
|
|
440 |
| Universal of bool option * typ
|
|
441 |
| Equational of bool option * typ
|
|
442 |
| Atomic of bool option
|
|
443 |
| Implicational of bool option
|
|
444 |
|
|
445 |
exception UNPOLARISED of term
|
|
446 |
(*Remove "= $true" or "= $false$ from the edge
|
|
447 |
of a formula. Use "try" in case formula is not
|
|
448 |
polarised.*)
|
|
449 |
fun remove_polarity strict formula =
|
|
450 |
case try HOLogic.dest_eq formula of
|
|
451 |
NONE => if strict then raise (UNPOLARISED formula)
|
|
452 |
else (formula, true)
|
|
453 |
| SOME (x, p as @{term True}) => (x, true)
|
|
454 |
| SOME (x, p as @{term False}) => (x, false)
|
|
455 |
| SOME (x, _) =>
|
|
456 |
if strict then raise (UNPOLARISED formula)
|
|
457 |
else (formula, true)
|
|
458 |
|
|
459 |
(*flattens a formula wrt associative operators*)
|
|
460 |
fun flatten formula_kind formula =
|
|
461 |
let
|
|
462 |
fun is_conj (Const (@{const_name HOL.conj}, _) $ _ $ _) = true
|
|
463 |
| is_conj _ = false
|
|
464 |
fun is_disj (Const (@{const_name HOL.disj}, _) $ _ $ _) = true
|
|
465 |
| is_disj _ = false
|
|
466 |
fun is_iff (Const (@{const_name HOL.eq}, ty) $ _ $ _) =
|
|
467 |
ty = ([HOLogic.boolT, HOLogic.boolT] ---> HOLogic.boolT)
|
|
468 |
| is_iff _ = false
|
|
469 |
|
|
470 |
fun flatten' formula acc =
|
|
471 |
case formula of
|
|
472 |
Const (@{const_name HOL.conj}, _) $ t1 $ t2 =>
|
|
473 |
(case formula_kind of
|
|
474 |
Conjunctive _ =>
|
|
475 |
let
|
|
476 |
val left =
|
|
477 |
if is_conj t1 then flatten' t1 acc else (t1 :: acc)
|
|
478 |
in
|
|
479 |
if is_conj t2 then flatten' t2 left else (t2 :: left)
|
|
480 |
end
|
|
481 |
| _ => formula :: acc)
|
|
482 |
| Const (@{const_name HOL.disj}, _) $ t1 $ t2 =>
|
|
483 |
(case formula_kind of
|
|
484 |
Disjunctive _ =>
|
|
485 |
let
|
|
486 |
val left =
|
|
487 |
if is_disj t1 then flatten' t1 acc else (t1 :: acc)
|
|
488 |
in
|
|
489 |
if is_disj t2 then flatten' t2 left else (t2 :: left)
|
|
490 |
end
|
|
491 |
| _ => formula :: acc)
|
|
492 |
| Const (@{const_name HOL.eq}, ty) $ t1 $ t2 =>
|
|
493 |
if ty = ([HOLogic.boolT, HOLogic.boolT] ---> HOLogic.boolT) then
|
|
494 |
case formula_kind of
|
|
495 |
Biimplicational _ =>
|
|
496 |
let
|
|
497 |
val left =
|
|
498 |
if is_iff t1 then flatten' t1 acc else (t1 :: acc)
|
|
499 |
in
|
|
500 |
if is_iff t2 then flatten' t2 left else (t2 :: left)
|
|
501 |
end
|
|
502 |
| _ => formula :: acc
|
|
503 |
else formula :: acc
|
|
504 |
| _ => [formula]
|
|
505 |
|
|
506 |
val formula' = try_dest_Trueprop formula
|
|
507 |
in
|
|
508 |
case formula_kind of
|
|
509 |
Conjunctive (SOME _) =>
|
|
510 |
remove_polarity false formula'
|
|
511 |
|> fst
|
|
512 |
|> (fn t => flatten' t [])
|
|
513 |
| Disjunctive (SOME _) =>
|
|
514 |
remove_polarity false formula'
|
|
515 |
|> fst
|
|
516 |
|> (fn t => flatten' t [])
|
|
517 |
| Biimplicational (SOME _) =>
|
|
518 |
remove_polarity false formula'
|
|
519 |
|> fst
|
|
520 |
|> (fn t => flatten' t [])
|
|
521 |
| _ => flatten' formula' []
|
|
522 |
end
|
|
523 |
|
|
524 |
fun node_info fms projector node_name =
|
|
525 |
case AList.lookup (op =) fms node_name of
|
|
526 |
NONE =>
|
|
527 |
raise (RECONSTRUCT ("node " ^ node_name ^
|
|
528 |
" doesn't exist"))
|
|
529 |
| SOME info => projector info
|
|
530 |
|
|
531 |
(*Given a list of parent infos, extract the parent node names
|
|
532 |
and the additional info (e.g., if there was an instantiation
|
|
533 |
in addition to the inference).
|
|
534 |
if "filtered"=true then exclude axiom and definition parents*)
|
|
535 |
fun dest_parent_infos filtered fms parent_infos : {name : string, details : TPTP_Proof.parent_detail list} list =
|
|
536 |
let
|
|
537 |
(*Removes "definition" dependencies since these play no
|
|
538 |
logical role -- i.e. they just give the expansions of
|
|
539 |
constants.
|
|
540 |
Removes "axiom" dependencies since these do not need to
|
|
541 |
be derived; the reconstruction handler in "leo2_tac" can
|
|
542 |
pick up the relevant axioms (using the info in the proof
|
|
543 |
annotation) and use them in its reconstruction.
|
|
544 |
*)
|
|
545 |
val filter_deps =
|
|
546 |
List.filter (fn {name, ...} =>
|
|
547 |
let
|
|
548 |
val role = node_info fms #role name
|
|
549 |
in role <> TPTP_Syntax.Role_Definition andalso
|
|
550 |
role <> TPTP_Syntax.Role_Axiom
|
|
551 |
end)
|
|
552 |
val parent_nodelist =
|
|
553 |
parent_infos
|
|
554 |
|> map (fn n =>
|
|
555 |
case n of
|
|
556 |
TPTP_Proof.Parent parent => {name = parent, details = []}
|
|
557 |
| TPTP_Proof.ParentWithDetails (parent, details) =>
|
|
558 |
{name = parent, details = details})
|
|
559 |
in
|
|
560 |
parent_nodelist
|
|
561 |
|> filtered ? filter_deps
|
|
562 |
end
|
|
563 |
|
|
564 |
fun parents_of_node fms n =
|
|
565 |
case node_info fms #source_inf_opt n of
|
|
566 |
NONE => []
|
|
567 |
| SOME (TPTP_Proof.File _) => []
|
|
568 |
| SOME (TPTP_Proof.Inference (_, _ : TPTP_Proof.useful_info_as list, parent_infos)) =>
|
|
569 |
dest_parent_infos false fms parent_infos
|
|
570 |
|> map #name
|
|
571 |
|
|
572 |
exception FIND_ANCESTOR_USING_RULE of string
|
|
573 |
(*BFS for an ancestor inference involving a specific rule*)
|
|
574 |
fun find_ancestor_using_rule pannot inference_rule (fringe : string list) : string =
|
|
575 |
if null fringe then
|
|
576 |
raise (FIND_ANCESTOR_USING_RULE inference_rule)
|
|
577 |
else
|
|
578 |
case node_info (#meta pannot) #source_inf_opt (hd fringe) of
|
|
579 |
NONE => find_ancestor_using_rule pannot inference_rule (tl fringe)
|
|
580 |
| SOME (TPTP_Proof.File _) => find_ancestor_using_rule pannot inference_rule (tl fringe)
|
|
581 |
| SOME (TPTP_Proof.Inference (rule_name, _ : TPTP_Proof.useful_info_as list, parent_infos)) =>
|
|
582 |
if rule_name = inference_rule then hd fringe
|
|
583 |
else
|
|
584 |
find_ancestor_using_rule pannot inference_rule
|
|
585 |
(tl fringe @
|
|
586 |
map #name (dest_parent_infos true (#meta pannot) parent_infos))
|
|
587 |
|
|
588 |
(*Given a node in the proof, produce the term representing the inference
|
|
589 |
that took place in that step, the inference rule used, and which
|
|
590 |
other (non-axiom and non-definition) nodes participated in the
|
|
591 |
inference*)
|
|
592 |
fun inference_at_node thy (prob_name : TPTP_Problem_Name.problem_name)
|
|
593 |
(fms : formula_meaning list) from : rule_info option =
|
|
594 |
let
|
|
595 |
exception INFERENCE_AT_NODE of string
|
|
596 |
|
|
597 |
(*lookup formula associated with a node*)
|
|
598 |
val fmla_of_node =
|
|
599 |
node_info fms #fmla
|
|
600 |
#> try_dest_Trueprop
|
|
601 |
|
|
602 |
fun build_inference_info rule_name parent_infos =
|
|
603 |
let
|
|
604 |
val _ = @{assert} (not (null parent_infos))
|
|
605 |
|
|
606 |
(*hypothesis formulas (with bindings already
|
|
607 |
instantiated during the proof-transformation
|
|
608 |
applied when loading the proof),
|
|
609 |
including any axioms or definitions*)
|
|
610 |
val parent_nodes =
|
|
611 |
dest_parent_infos false fms parent_infos
|
|
612 |
|> map #name
|
|
613 |
|
|
614 |
val parent_fmlas = map fmla_of_node (rev(*FIXME can do away with this? it matters because of order of conjunction. is there a matching rev elsewhere?*) parent_nodes)
|
|
615 |
|
|
616 |
val inference_term =
|
|
617 |
if null parent_fmlas then
|
|
618 |
fmla_of_node from
|
|
619 |
|> HOLogic.mk_Trueprop
|
|
620 |
else
|
|
621 |
Logic.mk_implies
|
|
622 |
(fold
|
|
623 |
(curry HOLogic.mk_conj)
|
|
624 |
(tl parent_fmlas)
|
|
625 |
(hd parent_fmlas)
|
|
626 |
|> HOLogic.mk_Trueprop,
|
|
627 |
fmla_of_node from |> HOLogic.mk_Trueprop)
|
|
628 |
in
|
|
629 |
SOME {inference_name = rule_name,
|
|
630 |
inference_fmla = inference_term,
|
|
631 |
parents = parent_nodes}
|
|
632 |
end
|
|
633 |
in
|
|
634 |
(*examine node's "source" annotation: we're only interested
|
|
635 |
if it's an inference*)
|
|
636 |
case node_info fms #source_inf_opt from of
|
|
637 |
NONE => NONE
|
|
638 |
| SOME (TPTP_Proof.File _) => NONE
|
|
639 |
| SOME (TPTP_Proof.Inference (rule_name, _ : TPTP_Proof.useful_info_as list, parent_infos)) =>
|
|
640 |
if List.null parent_infos then
|
|
641 |
raise (INFERENCE_AT_NODE
|
|
642 |
("empty parent list for node " ^
|
|
643 |
from ^ ": check proof format"))
|
|
644 |
else
|
|
645 |
build_inference_info rule_name parent_infos
|
|
646 |
end
|
|
647 |
|
|
648 |
|
|
649 |
(** Proof skeleton **)
|
|
650 |
|
|
651 |
(* Emulating skeleton steps *)
|
|
652 |
|
|
653 |
(*
|
|
654 |
Builds a rule (thm) of the following form:
|
|
655 |
|
|
656 |
|
|
657 |
prem1 premn
|
|
658 |
... ... ...
|
|
659 |
major_prem conc1 concn
|
|
660 |
-----------------------------------------------
|
|
661 |
conclusion
|
|
662 |
|
|
663 |
where major_prem is a disjunction of prem1,...,premn.
|
|
664 |
*)
|
|
665 |
fun make_elimination_rule_t ctxt major_prem prems_and_concs conclusion =
|
|
666 |
let
|
|
667 |
val thy = Proof_Context.theory_of ctxt
|
|
668 |
val minor_prems =
|
|
669 |
map (fn (v, conc) =>
|
|
670 |
Logic.mk_implies (v, HOLogic.mk_Trueprop conc))
|
|
671 |
prems_and_concs
|
|
672 |
in
|
|
673 |
(Logic.list_implies
|
|
674 |
(major_prem :: minor_prems,
|
|
675 |
conclusion))
|
|
676 |
end
|
|
677 |
|
|
678 |
(*In summary, we emulate an n-way splitting rule via an n-way
|
|
679 |
disjunction elimination.
|
|
680 |
|
|
681 |
Given a split formula and conclusion, we prove a rule which
|
|
682 |
simulates the split. The conclusion is assumed to be a conjunction
|
|
683 |
of conclusions for each branch of the split. The
|
|
684 |
"minor_prem_assumptions" are the assumptions discharged in each
|
|
685 |
branch; they're passed to the function to make sure that the
|
|
686 |
generated rule is compatible with the skeleton (since the skeleton
|
|
687 |
fixes the "order" of the reconstruction, based on the proof's
|
|
688 |
structure).
|
|
689 |
|
|
690 |
Concretely, if P is "(_ & _) = $false" or "(_ | _) = $true" then
|
|
691 |
splitting behaves as follows:
|
|
692 |
|
|
693 |
P
|
|
694 |
-------------------------------
|
|
695 |
_ = $false _ = $false
|
|
696 |
... ... ...
|
|
697 |
R1 Rn
|
|
698 |
-------------------------------
|
|
699 |
R1 & ... & Rn
|
|
700 |
|
|
701 |
Splitting (binary) iffs works as follows:
|
|
702 |
|
|
703 |
(A <=> B) = $false
|
|
704 |
------------------------------------------
|
|
705 |
(A => B) = $false (B => A) = $false
|
|
706 |
... ...
|
|
707 |
R1 R2
|
|
708 |
------------------------------------------
|
|
709 |
R1 & R2
|
|
710 |
*)
|
|
711 |
fun simulate_split ctxt split_fmla minor_prem_assumptions conclusion =
|
|
712 |
let
|
|
713 |
val prems_and_concs =
|
|
714 |
ListPair.zip (minor_prem_assumptions, flatten (Conjunctive NONE) conclusion)
|
|
715 |
|
|
716 |
val rule_t = make_elimination_rule_t ctxt split_fmla prems_and_concs conclusion
|
|
717 |
|
|
718 |
(*these are replaced by fresh variables in the abstract term*)
|
|
719 |
val abstraction_subterms =
|
|
720 |
(map (try_dest_Trueprop #> remove_polarity true #> fst)
|
|
721 |
minor_prem_assumptions)
|
|
722 |
|
|
723 |
(*generate an abstract rule as a term...*)
|
|
724 |
val abs_rule_t =
|
|
725 |
abstract
|
|
726 |
abstraction_subterms
|
|
727 |
rule_t
|
|
728 |
|> snd (*ignore mapping info. this is a bit wasteful*)
|
|
729 |
(*FIXME optimisation: instead on relying on diff
|
|
730 |
to regenerate this info, could use it directly*)
|
|
731 |
|
|
732 |
(*...and validate the abstract rule*)
|
|
733 |
val abs_rule_thm =
|
|
734 |
Goal.prove ctxt [] [] abs_rule_t
|
|
735 |
(fn pdata => HEADGOAL (blast_tac (#context pdata)))
|
|
736 |
|> Drule.export_without_context
|
|
737 |
in
|
|
738 |
(*Instantiate the abstract rule based on the contents of the
|
|
739 |
required instance*)
|
|
740 |
diff_and_instantiate ctxt abs_rule_thm (prop_of abs_rule_thm) rule_t
|
|
741 |
end
|
|
742 |
|
|
743 |
|
|
744 |
(* Building the skeleton *)
|
|
745 |
|
|
746 |
type step_id = string
|
|
747 |
datatype rolling_stock =
|
|
748 |
Step of step_id
|
|
749 |
| Assumed
|
|
750 |
| Unconjoin
|
|
751 |
| Split of step_id (*where split occurs*) *
|
|
752 |
step_id (*where split ends*) *
|
|
753 |
step_id list (*children of the split*)
|
|
754 |
| Synth_step of step_id (*A step which doesn't necessarily appear in
|
|
755 |
the original proof, or which has been modified slightly for better
|
|
756 |
handling by Isabelle*) (*FIXME "inodes" should be made into Synth_steps*)
|
|
757 |
| Annotated_step of step_id * string (*Same interpretation as
|
|
758 |
"Step", except that additional information is attached. This is
|
|
759 |
currently used for debugging: Steps are mapped to Annotated_steps
|
|
760 |
and their rule names are included as strings*)
|
|
761 |
| Definition of step_id (*Mirrors TPTP role*)
|
|
762 |
| Axiom of step_id (*Mirrors TPTP role*)
|
|
763 |
(* | Derived of step_id -- to be used by memoization*)
|
|
764 |
| Caboose
|
|
765 |
|
|
766 |
fun stock_to_string (Step n) = n
|
|
767 |
| stock_to_string (Annotated_step (n, anno)) = n ^ "(" ^ anno ^ ")"
|
|
768 |
| stock_to_string _ = error "Stock is not a step" (*FIXME more meaningful message*)
|
|
769 |
|
|
770 |
fun filter_by_role tptp_role =
|
|
771 |
filter
|
|
772 |
(fn (_, info) =>
|
|
773 |
#role info = tptp_role)
|
|
774 |
|
|
775 |
fun filter_by_name node_name =
|
|
776 |
filter
|
|
777 |
(fn (n, _) =>
|
|
778 |
n = node_name)
|
|
779 |
|
|
780 |
exception NO_MARKER_NODE
|
|
781 |
(*We fall back on node "1" in case the proof is not that of a theorem*)
|
|
782 |
fun proof_beginning_node fms =
|
|
783 |
let
|
|
784 |
val result =
|
|
785 |
cascaded_filter_single true
|
|
786 |
[filter_by_role TPTP_Syntax.Role_Conjecture,
|
|
787 |
filter_by_name "1"] (*FIXME const*)
|
|
788 |
fms
|
|
789 |
in
|
|
790 |
case result of
|
|
791 |
SOME x => fst x (*get the node name*)
|
|
792 |
| NONE => raise NO_MARKER_NODE
|
|
793 |
end
|
|
794 |
|
|
795 |
(*Get the name of the node where the proof ends*)
|
|
796 |
fun proof_end_node fms =
|
|
797 |
(*FIXME this isn't very nice: we assume that the last line in the
|
|
798 |
proof file is the closing line of the proof. It would be nicer if
|
|
799 |
such a line is specially marked (with a role), since there is no
|
|
800 |
obvious ordering on names, since they can be strings.
|
|
801 |
Another way would be to run an analysis on the graph to find
|
|
802 |
this node, since it has properties which should make it unique
|
|
803 |
in a graph*)
|
|
804 |
fms
|
|
805 |
|> hd (*since proof has been reversed prior*)
|
|
806 |
|> fst (*get node name*)
|
|
807 |
|
|
808 |
(*Generate list of (possibly reconstructed) inferences which can be
|
|
809 |
composed together to reconstruct the whole proof.*)
|
|
810 |
fun make_skeleton ctxt (pannot : proof_annotation) : rolling_stock list =
|
|
811 |
let
|
|
812 |
val thy = Proof_Context.theory_of ctxt
|
|
813 |
|
|
814 |
fun stock_is_ax_or_def (Axiom _) = true
|
|
815 |
| stock_is_ax_or_def (Definition _) = true
|
|
816 |
| stock_is_ax_or_def _ = false
|
|
817 |
|
|
818 |
fun stock_of n =
|
|
819 |
case node_info (#meta pannot) #role n of
|
|
820 |
TPTP_Syntax.Role_Definition => (true, Definition n)
|
|
821 |
| TPTP_Syntax.Role_Axiom => (true, Axiom n)
|
|
822 |
| _ => (false, Step n)
|
|
823 |
|
|
824 |
fun n_is_split_conjecture (inference_info : rule_info option) =
|
|
825 |
case inference_info of
|
|
826 |
NONE => false
|
|
827 |
| SOME inference_info => #inference_name inference_info = "split_conjecture"
|
|
828 |
|
|
829 |
(*Different kinds of inference sequences:
|
|
830 |
- Linear: (just add a step to the skeleton)
|
|
831 |
---...---
|
|
832 |
|
|
833 |
- Fan-in: (treat each in-path as conjoined with the others. Linearise all the paths, and concatenate them.)
|
|
834 |
/---...
|
|
835 |
------<
|
|
836 |
\---...
|
|
837 |
|
|
838 |
- Real split: Instead of treating as a conjunction, as in
|
|
839 |
normal fan-ins, we need to treat specially by looking
|
|
840 |
at the location where the split occurs, and turn the
|
|
841 |
split inference into a validity-preserving subproof.
|
|
842 |
As with fan-ins, we handle each fan-in path, and
|
|
843 |
concatenate.
|
|
844 |
/---...---\
|
|
845 |
------< >------
|
|
846 |
\---...---/
|
|
847 |
|
|
848 |
- Fake split: (treat like linear, since there isn't a split-node)
|
|
849 |
------<---...----------
|
|
850 |
|
|
851 |
Different kinds of sequences endings:
|
|
852 |
- "Stop before": Non-decreasing list of nodes where should terminate.
|
|
853 |
This starts off with the end node, and the split_nodes
|
|
854 |
will be added dynamically as the skeleton is built.
|
|
855 |
- Axiom/Definition
|
|
856 |
*)
|
|
857 |
|
|
858 |
(*The following functions build the skeleton for the reconstruction starting
|
|
859 |
from the node labelled "n" and stopping just before an element in stop_just_befores*)
|
|
860 |
(*FIXME could throw exception if none of stop_just_befores is ever encountered*)
|
|
861 |
|
|
862 |
(*This approach below is naive because it linearises the proof DAG, and this would
|
|
863 |
duplicate some effort if the DAG isn't already linear.*)
|
|
864 |
exception SKELETON
|
|
865 |
|
|
866 |
fun check_parents stop_just_befores n =
|
|
867 |
let
|
|
868 |
val parents = parents_of_node (#meta pannot) n
|
|
869 |
in
|
|
870 |
if length parents = 1 then
|
|
871 |
AList.lookup (op =) stop_just_befores (the_single parents)
|
|
872 |
else
|
|
873 |
NONE
|
|
874 |
end
|
|
875 |
|
|
876 |
fun naive_skeleton' stop_just_befores n =
|
|
877 |
case check_parents stop_just_befores n of
|
|
878 |
SOME skel => skel
|
|
879 |
| NONE =>
|
|
880 |
let
|
|
881 |
val inference_info = inference_at_node thy (#problem_name pannot) (#meta pannot) n
|
|
882 |
in
|
|
883 |
if is_none inference_info then
|
|
884 |
(*this is the case for the conjecture, definitions and axioms*)
|
|
885 |
if node_info (#meta pannot) #role n = TPTP_Syntax.Role_Definition then
|
|
886 |
[(Definition n), Assumed]
|
|
887 |
else if node_info (#meta pannot) #role n = TPTP_Syntax.Role_Axiom then
|
|
888 |
[Axiom n]
|
|
889 |
else raise SKELETON
|
|
890 |
else
|
|
891 |
let
|
|
892 |
val inference_info = the inference_info
|
|
893 |
val parents = #parents inference_info
|
|
894 |
in
|
|
895 |
(*FIXME memoize antecedent_steps?*)
|
|
896 |
if #inference_name inference_info = "solved_all_splits" andalso length parents > 1 then
|
|
897 |
(*splitting involves fanning out then in; this is to be
|
|
898 |
treated different than other fan-out-ins.*)
|
|
899 |
let
|
|
900 |
(*find where the proofs fanned-out: pick some antecedent,
|
|
901 |
then find ancestor to use a "split_conjecture" inference.*)
|
|
902 |
(*NOTE we assume that splits can't be nested*)
|
|
903 |
val split_node =
|
|
904 |
find_ancestor_using_rule pannot "split_conjecture" [hd parents]
|
|
905 |
|> parents_of_node (#meta pannot)
|
|
906 |
|> the_single
|
|
907 |
|
|
908 |
(*compute the skeletons starting at parents to either the split_node
|
|
909 |
if the antecedent is descended from the split_node, or the
|
|
910 |
stop_just_before otherwise*)
|
|
911 |
val skeletons_up =
|
|
912 |
map (naive_skeleton' ((split_node, [Assumed]) :: stop_just_befores)) parents
|
|
913 |
in
|
|
914 |
(*point to the split node, so that custom rule can be built later on*)
|
|
915 |
Step n :: (Split (split_node, n, parents)) :: (*this will create the elimination rule*)
|
|
916 |
naive_skeleton' stop_just_befores split_node @ (*this will discharge the major premise*)
|
|
917 |
List.concat skeletons_up @ [Assumed] (*this will discharge the minor premises*)
|
|
918 |
end
|
|
919 |
else if length parents > 1 then
|
|
920 |
(*Handle fan-in nodes which aren't split-sinks by
|
|
921 |
enclosing each branch but one in conjI-assumption invocations*)
|
|
922 |
let
|
|
923 |
val skeletons_up =
|
|
924 |
map (naive_skeleton' stop_just_befores) parents
|
|
925 |
in
|
|
926 |
Step n :: concat_between skeletons_up (SOME Unconjoin, NONE) @ [Assumed]
|
|
927 |
end
|
|
928 |
else
|
|
929 |
Step n :: naive_skeleton' stop_just_befores (the_single parents)
|
|
930 |
end
|
|
931 |
end
|
|
932 |
in
|
|
933 |
if List.null (#meta pannot) then [] (*in case "proof" file is empty*)
|
|
934 |
else
|
|
935 |
naive_skeleton'
|
|
936 |
[(proof_beginning_node (#meta pannot), [Assumed])]
|
|
937 |
(proof_end_node (#meta pannot))
|
|
938 |
(*make last step the Caboose*)
|
|
939 |
|> rev |> tl |> cons Caboose |> rev (*FIXME hacky*)
|
|
940 |
end
|
|
941 |
|
|
942 |
|
|
943 |
(* Using the skeleton *)
|
|
944 |
|
|
945 |
exception SKELETON
|
|
946 |
local
|
|
947 |
(*Change the negated assumption (which is output by the contradiction rule) into
|
|
948 |
a form familiar to Leo2*)
|
|
949 |
val neg_eq_false =
|
|
950 |
@{lemma "!! P. (~ P) ==> (P = False)" by auto}
|
|
951 |
|
|
952 |
(*FIXME this is just a dummy thm to annotate the assumption tac "atac"*)
|
|
953 |
val solved_all_splits =
|
|
954 |
@{lemma "False = True ==> False" by auto}
|
|
955 |
|
|
956 |
fun skel_to_naive_tactic ctxt prover_tac prob_name skel memo = fn st =>
|
|
957 |
let
|
|
958 |
val thy = Proof_Context.theory_of ctxt
|
|
959 |
val pannot = get_pannot_of_prob thy prob_name
|
|
960 |
fun tac_and_memo node memo =
|
|
961 |
case AList.lookup (op =) memo node of
|
|
962 |
NONE =>
|
|
963 |
let
|
|
964 |
val tac =
|
|
965 |
(*FIXME formula_sizelimit not being
|
|
966 |
checked here*)
|
|
967 |
prover_tac ctxt prob_name node
|
|
968 |
in (tac, (node, tac) :: memo) end
|
|
969 |
| SOME tac => (tac, memo)
|
|
970 |
fun rest skel' memo =
|
|
971 |
skel_to_naive_tactic ctxt prover_tac prob_name skel' memo
|
|
972 |
|
|
973 |
val tactic =
|
|
974 |
if null skel then
|
|
975 |
raise SKELETON (*FIXME or classify it as a Caboose: TRY (HEADGOAL atac) *)
|
|
976 |
else
|
|
977 |
case hd skel of
|
|
978 |
Assumed => TRY (HEADGOAL atac) THEN rest (tl skel) memo
|
|
979 |
| Caboose => TRY (HEADGOAL atac)
|
|
980 |
| Unconjoin => rtac @{thm conjI} 1 THEN rest (tl skel) memo
|
|
981 |
| Split (split_node, solved_node, antes) =>
|
|
982 |
let
|
|
983 |
val split_fmla = node_info (#meta pannot) #fmla split_node
|
|
984 |
val conclusion =
|
|
985 |
(inference_at_node thy prob_name (#meta pannot) solved_node
|
|
986 |
|> the
|
|
987 |
|> #inference_fmla)
|
|
988 |
|> Logic.dest_implies (*FIXME there might be !!-variables?*)
|
|
989 |
|> #1
|
|
990 |
val minor_prems_assumps =
|
|
991 |
map (fn ante => find_ancestor_using_rule pannot "split_conjecture" [ante]) antes
|
|
992 |
|> map (node_info (#meta pannot) #fmla)
|
|
993 |
val split_thm =
|
|
994 |
simulate_split ctxt split_fmla minor_prems_assumps conclusion
|
|
995 |
in
|
|
996 |
rtac split_thm 1 THEN rest (tl skel) memo
|
|
997 |
end
|
|
998 |
| Step s =>
|
|
999 |
let
|
|
1000 |
val (tac, memo') = tac_and_memo s memo
|
|
1001 |
in
|
|
1002 |
rtac tac 1 THEN rest (tl skel) memo'
|
|
1003 |
end
|
|
1004 |
| Definition n =>
|
|
1005 |
let
|
|
1006 |
val def_thm =
|
|
1007 |
case AList.lookup (op =) (#defs pannot) n of
|
|
1008 |
NONE => error ("Did not find definition: " ^ n)
|
|
1009 |
| SOME binding =>
|
|
1010 |
Binding.dest binding
|
|
1011 |
|> #3
|
|
1012 |
|> Global_Theory.get_thm thy
|
|
1013 |
in
|
|
1014 |
rtac def_thm 1 THEN rest (tl skel) memo
|
|
1015 |
end
|
|
1016 |
| Axiom n =>
|
|
1017 |
let
|
|
1018 |
val ax_thm =
|
|
1019 |
case AList.lookup (op =) (#axs pannot) n of
|
|
1020 |
NONE => error ("Did not find axiom: " ^ n)
|
|
1021 |
| SOME binding =>
|
|
1022 |
Binding.dest binding
|
|
1023 |
|> #3
|
|
1024 |
|> Global_Theory.get_thm thy
|
|
1025 |
in
|
|
1026 |
rtac ax_thm 1 THEN rest (tl skel) memo
|
|
1027 |
end
|
|
1028 |
| _ => raise SKELETON
|
|
1029 |
in tactic st end
|
|
1030 |
(*FIXME fuse these*)
|
|
1031 |
(*As above, but creates debug-friendly tactic.
|
|
1032 |
This is also used for "partial proof reconstruction"*)
|
|
1033 |
fun skel_to_naive_tactic_dbg prover_tac ctxt prob_name skel (memo : (string * (thm * tactic) option) list) =
|
|
1034 |
let
|
|
1035 |
val thy = Proof_Context.theory_of ctxt
|
|
1036 |
val pannot = get_pannot_of_prob thy prob_name
|
|
1037 |
|
|
1038 |
fun rtac_wrap thm_f i = fn st =>
|
|
1039 |
let
|
|
1040 |
val thy = Thm.theory_of_thm st
|
|
1041 |
in
|
|
1042 |
rtac (thm_f thy) i st
|
|
1043 |
end
|
|
1044 |
|
|
1045 |
(*Some nodes don't have an inference name, such as the conjecture,
|
|
1046 |
definitions and axioms. Such nodes shouldn't appear in the
|
|
1047 |
skeleton.*)
|
|
1048 |
fun inference_name_of_node node =
|
|
1049 |
case AList.lookup (op =) (#meta pannot) node of
|
|
1050 |
NONE => (warning "Inference step lacks an inference name"; "(Shouldn't be here)")
|
|
1051 |
| SOME info =>
|
|
1052 |
case #source_inf_opt info of
|
|
1053 |
SOME (TPTP_Proof.Inference (infname, _, _)) =>
|
|
1054 |
infname
|
|
1055 |
| _ => (warning "Inference step lacks an inference name"; "(Shouldn't be here)")
|
|
1056 |
|
|
1057 |
fun inference_fmla node =
|
|
1058 |
case inference_at_node thy prob_name (#meta pannot) node of
|
|
1059 |
NONE => NONE
|
|
1060 |
| SOME {inference_fmla, ...} => SOME inference_fmla
|
|
1061 |
|
|
1062 |
fun rest memo' ctxt' = skel_to_naive_tactic_dbg prover_tac ctxt' prob_name (tl skel) memo'
|
|
1063 |
(*reconstruct the inference. also set timeout in case
|
|
1064 |
tactic takes too long*)
|
|
1065 |
val try_make_step =
|
|
1066 |
(*FIXME const timeout*)
|
|
1067 |
(* TimeLimit.timeLimit (Time.fromSeconds 5) *)
|
|
1068 |
(fn ctxt' =>
|
|
1069 |
let
|
|
1070 |
fun thm ctxt'' = prover_tac ctxt'' prob_name (hd skel |> stock_to_string)
|
|
1071 |
val reconstructed_inference = thm ctxt'
|
|
1072 |
val rec_inf_tac = fn st =>
|
|
1073 |
let
|
|
1074 |
val ctxt =
|
|
1075 |
Thm.theory_of_thm st
|
|
1076 |
|> Proof_Context.init_global
|
|
1077 |
in
|
|
1078 |
HEADGOAL (rtac (thm ctxt)) st
|
|
1079 |
end
|
|
1080 |
in (reconstructed_inference,
|
|
1081 |
rec_inf_tac)
|
|
1082 |
end)
|
|
1083 |
fun ignore_interpretation_exn f x = SOME (f x)
|
|
1084 |
handle
|
|
1085 |
INTERPRET_INFERENCE => NONE
|
|
1086 |
| exn => reraise exn
|
|
1087 |
in
|
|
1088 |
if List.null skel then
|
|
1089 |
raise SKELETON
|
|
1090 |
(*FIXME or classify it as follows:
|
|
1091 |
[(Caboose,
|
|
1092 |
prop_of @{thm asm_rl}
|
|
1093 |
|> SOME,
|
|
1094 |
SOME (@{thm asm_rl}, TRY (HEADGOAL atac)))]
|
|
1095 |
*)
|
|
1096 |
else
|
|
1097 |
case hd skel of
|
|
1098 |
Assumed =>
|
|
1099 |
(hd skel,
|
|
1100 |
prop_of @{thm asm_rl}
|
|
1101 |
|> SOME,
|
|
1102 |
SOME (@{thm asm_rl}, TRY (HEADGOAL atac))) :: rest memo ctxt
|
|
1103 |
| Caboose =>
|
|
1104 |
[(Caboose,
|
|
1105 |
prop_of @{thm asm_rl}
|
|
1106 |
|> SOME,
|
|
1107 |
SOME (@{thm asm_rl}, TRY (HEADGOAL atac)))]
|
|
1108 |
| Unconjoin =>
|
|
1109 |
(hd skel,
|
|
1110 |
prop_of @{thm conjI}
|
|
1111 |
|> SOME,
|
|
1112 |
SOME (@{thm conjI}, rtac @{thm conjI} 1)) :: rest memo ctxt
|
|
1113 |
| Split (split_node, solved_node, antes) =>
|
|
1114 |
let
|
|
1115 |
val split_fmla = node_info (#meta pannot) #fmla split_node
|
|
1116 |
val conclusion =
|
|
1117 |
(inference_at_node thy prob_name (#meta pannot) solved_node
|
|
1118 |
|> the
|
|
1119 |
|> #inference_fmla)
|
|
1120 |
|> Logic.dest_implies (*FIXME there might be !!-variables?*)
|
|
1121 |
|> #1
|
|
1122 |
val minor_prems_assumps =
|
|
1123 |
map (fn ante => find_ancestor_using_rule pannot "split_conjecture" [ante]) antes
|
|
1124 |
|> map (node_info (#meta pannot) #fmla)
|
|
1125 |
val split_thm =
|
|
1126 |
simulate_split ctxt split_fmla minor_prems_assumps conclusion
|
|
1127 |
in
|
|
1128 |
(hd skel,
|
|
1129 |
prop_of split_thm
|
|
1130 |
|> SOME,
|
|
1131 |
SOME (split_thm, rtac split_thm 1)) :: rest memo ctxt
|
|
1132 |
end
|
|
1133 |
| Step node =>
|
|
1134 |
let
|
|
1135 |
val inference_name = inference_name_of_node node
|
|
1136 |
val inference_fmla = inference_fmla node
|
|
1137 |
|
|
1138 |
(*FIXME debugging code
|
|
1139 |
val _ =
|
|
1140 |
if Config.get ctxt tptp_trace_reconstruction then
|
|
1141 |
(tracing ("handling node " ^ node);
|
|
1142 |
tracing ("inference " ^ inference_name);
|
|
1143 |
if is_some inference_fmla then
|
|
1144 |
tracing ("formula size " ^ Int.toString (Term.size_of_term (the inference_fmla)))
|
|
1145 |
else ()(*;
|
|
1146 |
tracing ("formula " ^ @{make_string inference_fmla}) *))
|
|
1147 |
else ()*)
|
|
1148 |
|
|
1149 |
val (inference_instance_thm, memo', ctxt') =
|
|
1150 |
case AList.lookup (op =) memo node of
|
|
1151 |
NONE =>
|
|
1152 |
let
|
|
1153 |
val (thm, ctxt') =
|
|
1154 |
(*Instead of NONE could have another value indicating that the formula was too big*)
|
|
1155 |
if is_some inference_fmla andalso
|
|
1156 |
(*FIXME could have different inference rules have different sizelimits*)
|
|
1157 |
exceeds_tptp_max_term_size ctxt (Term.size_of_term (the inference_fmla)) then
|
|
1158 |
(
|
|
1159 |
warning ("Gave up on node " ^ node ^ " because of fmla size " ^
|
|
1160 |
Int.toString (Term.size_of_term (the inference_fmla)));
|
|
1161 |
(NONE, ctxt)
|
|
1162 |
)
|
|
1163 |
else
|
|
1164 |
let
|
|
1165 |
val maybe_thm = ignore_interpretation_exn try_make_step ctxt
|
|
1166 |
val ctxt' =
|
|
1167 |
if is_some maybe_thm then
|
|
1168 |
the maybe_thm
|
|
1169 |
|> #1
|
|
1170 |
|> Thm.theory_of_thm |> Proof_Context.init_global
|
|
1171 |
else ctxt
|
|
1172 |
in
|
|
1173 |
(maybe_thm, ctxt')
|
|
1174 |
end
|
|
1175 |
in (thm, (node, thm) :: memo, ctxt') end
|
|
1176 |
| SOME maybe_thm => (maybe_thm, memo, ctxt)
|
|
1177 |
in
|
|
1178 |
(Annotated_step (node, inference_name),
|
|
1179 |
inference_fmla,
|
|
1180 |
inference_instance_thm) :: rest memo' ctxt'
|
|
1181 |
end
|
|
1182 |
| Definition n =>
|
|
1183 |
let
|
|
1184 |
fun def_thm thy =
|
|
1185 |
case AList.lookup (op =) (#defs pannot) n of
|
|
1186 |
NONE => error ("Did not find definition: " ^ n)
|
|
1187 |
| SOME binding =>
|
|
1188 |
Binding.dest binding
|
|
1189 |
|> #3
|
|
1190 |
|> Global_Theory.get_thm thy
|
|
1191 |
in
|
|
1192 |
(hd skel,
|
|
1193 |
prop_of (def_thm thy)
|
|
1194 |
|> SOME,
|
|
1195 |
SOME (def_thm thy,
|
|
1196 |
HEADGOAL (rtac_wrap def_thm))) :: rest memo ctxt
|
|
1197 |
end
|
|
1198 |
| Axiom n =>
|
|
1199 |
let
|
|
1200 |
val ax_thm =
|
|
1201 |
case AList.lookup (op =) (#axs pannot) n of
|
|
1202 |
NONE => error ("Did not find axiom: " ^ n)
|
|
1203 |
| SOME binding =>
|
|
1204 |
Binding.dest binding
|
|
1205 |
|> #3
|
|
1206 |
|> Global_Theory.get_thm thy
|
|
1207 |
in
|
|
1208 |
(hd skel,
|
|
1209 |
prop_of ax_thm
|
|
1210 |
|> SOME,
|
|
1211 |
SOME (ax_thm, rtac ax_thm 1)) :: rest memo ctxt
|
|
1212 |
end
|
|
1213 |
end
|
|
1214 |
|
|
1215 |
(*The next function handles cases where Leo2 doesn't include the solved_all_splits
|
|
1216 |
step at the end (e.g. because there wouldn't be a split -- the proof
|
|
1217 |
would be linear*)
|
|
1218 |
fun sas_if_needed_tac ctxt prob_name =
|
|
1219 |
let
|
|
1220 |
val thy = Proof_Context.theory_of ctxt
|
|
1221 |
val pannot = get_pannot_of_prob thy prob_name
|
|
1222 |
val last_inference_info_opt =
|
|
1223 |
find_first
|
|
1224 |
(fn (_, info) => #role info = TPTP_Syntax.Role_Plain)
|
|
1225 |
(#meta pannot)
|
|
1226 |
val last_inference_info =
|
|
1227 |
case last_inference_info_opt of
|
|
1228 |
NONE => NONE
|
|
1229 |
| SOME (_, info) => #source_inf_opt info
|
|
1230 |
in
|
|
1231 |
if is_some last_inference_info andalso
|
|
1232 |
TPTP_Proof.is_inference_called "solved_all_splits"
|
|
1233 |
(the last_inference_info)
|
|
1234 |
then (@{thm asm_rl}, all_tac)
|
|
1235 |
else (solved_all_splits, TRY (rtac solved_all_splits 1))
|
|
1236 |
end
|
|
1237 |
in
|
|
1238 |
(*Build a tactic from a skeleton. This is naive because it uses the naive skeleton.
|
|
1239 |
The inference interpretation ("prover_tac") is a parameter -- it would usually be
|
|
1240 |
different for different provers.*)
|
|
1241 |
fun naive_reconstruct_tac ctxt prover_tac prob_name =
|
|
1242 |
let
|
|
1243 |
val thy = Proof_Context.theory_of ctxt
|
|
1244 |
in
|
|
1245 |
rtac @{thm ccontr} 1
|
|
1246 |
THEN dtac neg_eq_false 1
|
|
1247 |
THEN (sas_if_needed_tac ctxt prob_name |> #2)
|
|
1248 |
THEN skel_to_naive_tactic ctxt prover_tac prob_name
|
|
1249 |
(make_skeleton ctxt
|
|
1250 |
(get_pannot_of_prob thy prob_name)) []
|
|
1251 |
end
|
|
1252 |
|
|
1253 |
(*As above, but generates a list of tactics. This is useful for debugging, to apply
|
|
1254 |
the tactics one by one manually.*)
|
|
1255 |
fun naive_reconstruct_tacs prover_tac prob_name ctxt =
|
|
1256 |
let
|
|
1257 |
val thy = Proof_Context.theory_of ctxt
|
|
1258 |
in
|
|
1259 |
(Synth_step "ccontr", prop_of @{thm ccontr} |> SOME,
|
|
1260 |
SOME (@{thm ccontr}, rtac @{thm ccontr} 1)) ::
|
|
1261 |
(Synth_step "neg_eq_false", prop_of neg_eq_false |> SOME,
|
|
1262 |
SOME (neg_eq_false, dtac neg_eq_false 1)) ::
|
|
1263 |
(Synth_step "sas_if_needed_tac", prop_of @{thm asm_rl}(*FIXME *) |> SOME,
|
|
1264 |
SOME (sas_if_needed_tac ctxt prob_name)) ::
|
|
1265 |
skel_to_naive_tactic_dbg prover_tac ctxt prob_name
|
|
1266 |
(make_skeleton ctxt
|
|
1267 |
(get_pannot_of_prob thy prob_name)) []
|
|
1268 |
end
|
|
1269 |
end
|
|
1270 |
|
|
1271 |
(*Produces a theorem given a tactic and a parsed proof. This function is handy
|
|
1272 |
to test reconstruction, since it automates the interpretation and proving of the
|
|
1273 |
parsed proof's goal.*)
|
|
1274 |
fun reconstruct ctxt tactic prob_name =
|
|
1275 |
let
|
|
1276 |
val thy = Proof_Context.theory_of ctxt
|
|
1277 |
val pannot = get_pannot_of_prob thy prob_name
|
|
1278 |
val goal =
|
|
1279 |
#meta pannot
|
|
1280 |
|> List.filter (fn (_, info) =>
|
|
1281 |
#role info = TPTP_Syntax.Role_Conjecture)
|
|
1282 |
in
|
|
1283 |
if null (#meta pannot) then
|
|
1284 |
(*since the proof is empty, return a trivial result.*)
|
|
1285 |
@{thm TrueI}
|
|
1286 |
else if null goal then
|
|
1287 |
raise (RECONSTRUCT "Proof lacks conjecture")
|
|
1288 |
else
|
|
1289 |
the_single goal
|
|
1290 |
|> snd |> #fmla
|
|
1291 |
|> (fn fmla => Goal.prove ctxt [] [] fmla (fn _ => tactic prob_name))
|
|
1292 |
end
|
|
1293 |
|
|
1294 |
|
|
1295 |
(** Skolemisation setup **)
|
|
1296 |
|
|
1297 |
(*Ignore these constants if they appear in the conclusion but not the hypothesis*)
|
|
1298 |
(*FIXME possibly incomplete*)
|
|
1299 |
val ignore_consts =
|
|
1300 |
[HOLogic.conj, HOLogic.disj, HOLogic.imp, HOLogic.Not]
|
|
1301 |
|
|
1302 |
(*Difference between the constants appearing between two terms, minus "ignore_consts"*)
|
|
1303 |
fun new_consts_between t1 t2 =
|
|
1304 |
List.filter
|
|
1305 |
(fn n => not (List.exists (fn n' => n' = n) ignore_consts))
|
|
1306 |
(list_diff (consts_in t2) (consts_in t1))
|
|
1307 |
|
|
1308 |
(*Generate definition binding for an equation*)
|
|
1309 |
fun mk_bind_eq prob_name params ((n, ty), t) =
|
|
1310 |
let
|
|
1311 |
val bnd =
|
|
1312 |
Binding.name (List.last (space_explode "." n) ^ "_def")
|
|
1313 |
|> Binding.qualify false (TPTP_Problem_Name.mangle_problem_name prob_name)
|
|
1314 |
val t' =
|
|
1315 |
Term.list_comb (Const (n, ty), params)
|
|
1316 |
|> rpair t
|
|
1317 |
|> HOLogic.mk_eq
|
|
1318 |
|> HOLogic.mk_Trueprop
|
|
1319 |
|> fold Logic.all params
|
|
1320 |
in
|
|
1321 |
(bnd, t')
|
|
1322 |
end
|
|
1323 |
|
|
1324 |
(*Generate binding for an axiom. Similar to "mk_bind_eq"*)
|
|
1325 |
fun mk_bind_ax prob_name node t =
|
|
1326 |
let
|
|
1327 |
val bnd =
|
|
1328 |
Binding.name node
|
|
1329 |
(*FIXME add suffix? e.g. ^ "_ax"*)
|
|
1330 |
|> Binding.qualify false (TPTP_Problem_Name.mangle_problem_name prob_name)
|
|
1331 |
in
|
|
1332 |
(bnd, t)
|
|
1333 |
end
|
|
1334 |
|
|
1335 |
(*Extract the constant name, type, and its definition*)
|
|
1336 |
fun get_defn_components
|
|
1337 |
(Const (@{const_name HOL.Trueprop}, _) $
|
|
1338 |
(Const (@{const_name HOL.eq}, _) $
|
|
1339 |
Const (name, ty) $ t)) = ((name, ty), t)
|
|
1340 |
|
|
1341 |
|
|
1342 |
(*** Proof transformations ***)
|
|
1343 |
|
|
1344 |
(*Transforms a proof_annotation value.
|
|
1345 |
Argument "f" is the proof transformer*)
|
|
1346 |
fun transf_pannot f (pannot : proof_annotation) : (theory * proof_annotation) =
|
|
1347 |
let
|
|
1348 |
val (thy', fms') = f (#meta pannot)
|
|
1349 |
in
|
|
1350 |
(thy',
|
|
1351 |
{problem_name = #problem_name pannot,
|
|
1352 |
skolem_defs = #skolem_defs pannot,
|
|
1353 |
defs = #defs pannot,
|
|
1354 |
axs = #axs pannot,
|
|
1355 |
meta = fms'})
|
|
1356 |
end
|
|
1357 |
|
|
1358 |
|
|
1359 |
(** Proof transformer to add virtual inference steps
|
|
1360 |
encoding "bind" annotations in Leo-II proofs **)
|
|
1361 |
|
|
1362 |
(*
|
|
1363 |
Involves finding an inference of this form:
|
|
1364 |
|
|
1365 |
(!x1 ... xn. F) ... Cn
|
|
1366 |
------------------------------------ (Rule name)
|
|
1367 |
G[t1/x1, ..., tn/xn]
|
|
1368 |
|
|
1369 |
and turn it into this:
|
|
1370 |
|
|
1371 |
|
|
1372 |
(!x1 ... xn. F)
|
|
1373 |
---------------------- bind
|
|
1374 |
F[t1/x1, ..., tn/xn] ... Cn
|
|
1375 |
-------------------------------------------- (Rule name)
|
|
1376 |
G
|
|
1377 |
|
|
1378 |
where "bind" is an inference rule (distinct from any rule name used
|
|
1379 |
by Leo2) to indicate such inferences. This transformation is used
|
|
1380 |
to factor out instantiations, thus allowing the reconstruction to
|
|
1381 |
focus on (Rule name) rather than "(Rule name) + instantiations".
|
|
1382 |
*)
|
|
1383 |
fun interpolate_binds prob_name thy fms : theory * formula_meaning list =
|
|
1384 |
let
|
|
1385 |
fun factor_out_bind target_node pinfo intermediate_thy =
|
|
1386 |
case pinfo of
|
|
1387 |
TPTP_Proof.ParentWithDetails (n, pdetails) =>
|
|
1388 |
(*create new node which contains the "bind" inference,
|
|
1389 |
to be added to graph*)
|
|
1390 |
let
|
|
1391 |
val (new_node_name, thy') = get_next_name intermediate_thy
|
|
1392 |
val orig_fmla = node_info fms #fmla n
|
|
1393 |
val target_fmla = node_info fms #fmla target_node
|
|
1394 |
val new_node =
|
|
1395 |
(new_node_name,
|
|
1396 |
{role = TPTP_Syntax.Role_Plain,
|
|
1397 |
fmla = apply_binding thy' prob_name orig_fmla target_fmla pdetails |> fst,
|
|
1398 |
source_inf_opt =
|
|
1399 |
SOME (TPTP_Proof.Inference (bindK, [], [pinfo]))})
|
|
1400 |
in
|
|
1401 |
((TPTP_Proof.Parent new_node_name, SOME new_node), thy')
|
|
1402 |
end
|
|
1403 |
| _ => ((pinfo, NONE), intermediate_thy)
|
|
1404 |
fun process_nodes (step as (n, data)) (intermediate_thy, rest) =
|
|
1405 |
case #source_inf_opt data of
|
|
1406 |
SOME (TPTP_Proof.Inference (inf_name, sinfos, pinfos)) =>
|
|
1407 |
let
|
|
1408 |
val ((pinfos', parent_nodes), thy') =
|
|
1409 |
fold_map (factor_out_bind n) pinfos intermediate_thy
|
|
1410 |
|> apfst ListPair.unzip
|
|
1411 |
val step' =
|
|
1412 |
(n, {role = #role data, fmla = #fmla data,
|
|
1413 |
source_inf_opt = SOME (TPTP_Proof.Inference (inf_name, sinfos, pinfos'))})
|
|
1414 |
in (thy', fold_options parent_nodes @ step' :: rest) end
|
|
1415 |
| _ => (intermediate_thy, step :: rest)
|
|
1416 |
in
|
|
1417 |
fold process_nodes fms (thy, [])
|
|
1418 |
(*new_nodes must come at the beginning, since we assume that the last line in a proof is the closing line*)
|
|
1419 |
|> apsnd rev
|
|
1420 |
end
|
|
1421 |
|
|
1422 |
|
|
1423 |
(** Proof transformer to add virtual inference steps
|
|
1424 |
encoding any transformation done immediately prior
|
|
1425 |
to a splitting step **)
|
|
1426 |
|
|
1427 |
(*
|
|
1428 |
Involves finding an inference of this form:
|
|
1429 |
|
|
1430 |
F = $false
|
|
1431 |
----------------------------------- split_conjecture
|
|
1432 |
(F1 = $false) ... (Fn = $false)
|
|
1433 |
|
|
1434 |
where F doesn't have an "and" or "iff" at the top level,
|
|
1435 |
and turn it into this:
|
|
1436 |
|
|
1437 |
F = $false
|
|
1438 |
----------------------------------- split_preprocessing
|
|
1439 |
(F1 % ... % Fn) = $false
|
|
1440 |
----------------------------------- split_conjecture
|
|
1441 |
(F1 = $false) ... (Fn = $false)
|
|
1442 |
|
|
1443 |
where "%" is either an "and" or an "iff" connective.
|
|
1444 |
This transformation is used to clarify the clause structure, to
|
|
1445 |
make it immediately "obvious" how splitting is taking place
|
|
1446 |
(by factoring out the other syntactic transformations -- e.g.
|
|
1447 |
related to quantifiers -- performed by Leo2). Having the clause
|
|
1448 |
in this "clearer" form makes the inference amenable to handling
|
|
1449 |
using the "abstraction" technique, which allows us to validate
|
|
1450 |
large inferences.
|
|
1451 |
*)
|
|
1452 |
exception PREPROCESS_SPLITS
|
|
1453 |
fun preprocess_splits prob_name thy fms : theory * formula_meaning list =
|
|
1454 |
let
|
|
1455 |
(*Simulate the transformation done by Leo2's preprocessing
|
|
1456 |
step during splitting.
|
|
1457 |
NOTE: we assume that the clause is a singleton
|
|
1458 |
|
|
1459 |
This transformation does the following:
|
|
1460 |
- miniscopes !-quantifiers (and recurs)
|
|
1461 |
- removes redundant ?-quantifiers (and recurs)
|
|
1462 |
- eliminates double negation (and recurs)
|
|
1463 |
- breaks up conjunction (and recurs)
|
|
1464 |
- expands iff (and doesn't recur)*)
|
|
1465 |
fun transform_fmla i fmla_t =
|
|
1466 |
case fmla_t of
|
|
1467 |
Const (@{const_name "HOL.All"}, ty) $ Abs (s, ty', t') =>
|
|
1468 |
let
|
|
1469 |
val (i', fmla_ts) = transform_fmla i t'
|
|
1470 |
in
|
|
1471 |
if i' > i then
|
|
1472 |
(i' + 1,
|
|
1473 |
map (fn t =>
|
|
1474 |
Const (@{const_name "HOL.All"}, ty) $ Abs (s, ty', t))
|
|
1475 |
fmla_ts)
|
|
1476 |
else (i, [fmla_t])
|
|
1477 |
end
|
|
1478 |
| Const (@{const_name "HOL.Ex"}, ty) $ Abs (s, ty', t') =>
|
|
1479 |
if loose_bvar (t', 0) then
|
|
1480 |
(i, [fmla_t])
|
|
1481 |
else transform_fmla (i + 1) t'
|
|
1482 |
| @{term HOL.Not} $ (@{term HOL.Not} $ t') =>
|
|
1483 |
transform_fmla (i + 1) t'
|
|
1484 |
| @{term HOL.conj} $ t1 $ t2 =>
|
|
1485 |
let
|
|
1486 |
val (i1, fmla_t1s) = transform_fmla (i + 1) t1
|
|
1487 |
val (i2, fmla_t2s) = transform_fmla (i + 1) t2
|
|
1488 |
in
|
|
1489 |
(i1 + i2 - i, fmla_t1s @ fmla_t2s)
|
|
1490 |
end
|
|
1491 |
| Const (@{const_name HOL.eq}, ty) $ t1 $ t2 =>
|
|
1492 |
let
|
|
1493 |
val (T1, (T2, res)) =
|
|
1494 |
dest_funT ty
|
|
1495 |
|> apsnd dest_funT
|
|
1496 |
in
|
|
1497 |
if T1 = HOLogic.boolT andalso T2 = HOLogic.boolT andalso
|
|
1498 |
res = HOLogic.boolT then
|
|
1499 |
(i + 1,
|
|
1500 |
[HOLogic.mk_imp (t1, t2),
|
|
1501 |
HOLogic.mk_imp (t2, t1)])
|
|
1502 |
else (i, [fmla_t])
|
|
1503 |
end
|
|
1504 |
| _ => (i, [fmla_t])
|
|
1505 |
|
|
1506 |
fun preprocess_split thy split_node_name fmla_t =
|
|
1507 |
(*create new node which contains the new inference,
|
|
1508 |
to be added to graph*)
|
|
1509 |
let
|
|
1510 |
val (node_name, thy') = get_next_name thy
|
|
1511 |
val (changes, fmla_conjs) =
|
|
1512 |
transform_fmla 0 fmla_t
|
|
1513 |
|> apsnd rev (*otherwise we run into problems because
|
|
1514 |
of commutativity of conjunction*)
|
|
1515 |
val target_fmla =
|
|
1516 |
fold (curry HOLogic.mk_conj) (tl fmla_conjs) (hd fmla_conjs)
|
|
1517 |
val new_node =
|
|
1518 |
(node_name,
|
|
1519 |
{role = TPTP_Syntax.Role_Plain,
|
|
1520 |
fmla =
|
|
1521 |
HOLogic.mk_eq (target_fmla, @{term False}) (*polarise*)
|
|
1522 |
|> HOLogic.mk_Trueprop,
|
|
1523 |
source_inf_opt =
|
|
1524 |
SOME (TPTP_Proof.Inference (split_preprocessingK, [], [TPTP_Proof.Parent split_node_name]))})
|
|
1525 |
in
|
|
1526 |
if changes = 0 then NONE
|
|
1527 |
else SOME (TPTP_Proof.Parent node_name, new_node, thy')
|
|
1528 |
end
|
|
1529 |
in
|
|
1530 |
fold
|
|
1531 |
(fn step as (n, data) => fn (intermediate_thy, redirections, rest) =>
|
|
1532 |
case #source_inf_opt data of
|
|
1533 |
SOME (TPTP_Proof.Inference
|
|
1534 |
(inf_name, sinfos, pinfos)) =>
|
|
1535 |
if inf_name <> "split_conjecture" then
|
|
1536 |
(intermediate_thy, redirections, step :: rest)
|
|
1537 |
else
|
|
1538 |
let
|
|
1539 |
(*
|
|
1540 |
NOTE: here we assume that the node only has one
|
|
1541 |
parent, and that there is no additional
|
|
1542 |
parent info.
|
|
1543 |
*)
|
|
1544 |
val split_node_name =
|
|
1545 |
case pinfos of
|
|
1546 |
[TPTP_Proof.Parent n] => n
|
|
1547 |
| _ => raise PREPROCESS_SPLITS
|
|
1548 |
(*check if we've already handled that already node*)
|
|
1549 |
in
|
|
1550 |
case AList.lookup (op =) redirections split_node_name of
|
|
1551 |
SOME preprocessed_split_node_name =>
|
|
1552 |
let
|
|
1553 |
val step' =
|
|
1554 |
apply_to_parent_info (fn _ => [TPTP_Proof.Parent preprocessed_split_node_name]) step
|
|
1555 |
in (intermediate_thy, redirections, step' :: rest) end
|
|
1556 |
| NONE =>
|
|
1557 |
let
|
|
1558 |
(*we know the polarity to be $false, from knowing Leo2*)
|
|
1559 |
val split_fmla =
|
|
1560 |
try_dest_Trueprop (node_info fms #fmla split_node_name)
|
|
1561 |
|> remove_polarity true
|
|
1562 |
|> fst
|
|
1563 |
|
|
1564 |
val preprocess_result =
|
|
1565 |
preprocess_split intermediate_thy
|
|
1566 |
split_node_name
|
|
1567 |
split_fmla
|
|
1568 |
in
|
|
1569 |
if is_none preprocess_result then
|
|
1570 |
(*no preprocessing done by Leo2, so no need to introduce
|
|
1571 |
a virtual inference. cache this result by
|
|
1572 |
redirecting the split_node to itself*)
|
|
1573 |
(intermediate_thy,
|
|
1574 |
(split_node_name, split_node_name) :: redirections,
|
|
1575 |
step :: rest)
|
|
1576 |
else
|
|
1577 |
let
|
|
1578 |
val (new_parent_info, new_parent_node, thy') = the preprocess_result
|
|
1579 |
val step' =
|
|
1580 |
(n, {role = #role data, fmla = #fmla data,
|
|
1581 |
source_inf_opt = SOME (TPTP_Proof.Inference (inf_name, sinfos, [new_parent_info]))})
|
|
1582 |
in
|
|
1583 |
(thy',
|
|
1584 |
(split_node_name, fst new_parent_node) :: redirections,
|
|
1585 |
step' :: new_parent_node :: rest)
|
|
1586 |
end
|
|
1587 |
end
|
|
1588 |
end
|
|
1589 |
| _ => (intermediate_thy, redirections, step :: rest))
|
|
1590 |
(rev fms) (*this allows us to put new inferences before other inferences which use them*)
|
|
1591 |
(thy, [], [])
|
|
1592 |
|> (fn (x, _, z) => (x, z)) (*discard redirection info*)
|
|
1593 |
end
|
|
1594 |
|
|
1595 |
|
|
1596 |
(** Proof transformer to remove repeated quantification **)
|
|
1597 |
|
|
1598 |
exception DROP_REPEATED_QUANTIFICATION
|
|
1599 |
fun drop_repeated_quantification thy (fms : formula_meaning list) : theory * formula_meaning list =
|
|
1600 |
let
|
|
1601 |
(*In case of repeated quantification, removes outer quantification.
|
|
1602 |
Only need to look at top-level, since the repeated quantification
|
|
1603 |
generally occurs at clause level*)
|
|
1604 |
fun remove_repeated_quantification seen t =
|
|
1605 |
case t of
|
|
1606 |
(*NOTE we're assuming that variables having the same name, have the same type throughout*)
|
|
1607 |
Const (@{const_name "HOL.All"}, ty) $ Abs (s, ty', t') =>
|
|
1608 |
let
|
|
1609 |
val (seen_so_far, seen') =
|
|
1610 |
case AList.lookup (op =) seen s of
|
|
1611 |
NONE => (0, (s, 0) :: seen)
|
|
1612 |
| SOME n => (n + 1, AList.update (op =) (s, n + 1) seen)
|
|
1613 |
val (pre_final_t, final_seen) = remove_repeated_quantification seen' t'
|
|
1614 |
val final_t =
|
|
1615 |
case AList.lookup (op =) final_seen s of
|
|
1616 |
NONE => raise DROP_REPEATED_QUANTIFICATION
|
|
1617 |
| SOME n =>
|
|
1618 |
if n > seen_so_far then pre_final_t
|
|
1619 |
else Const (@{const_name "HOL.All"}, ty) $ Abs (s, ty', pre_final_t)
|
|
1620 |
in (final_t, final_seen) end
|
|
1621 |
| _ => (t, seen)
|
|
1622 |
|
|
1623 |
fun remove_repeated_quantification' (n, {role, fmla, source_inf_opt}) =
|
|
1624 |
(n,
|
|
1625 |
{role = role,
|
|
1626 |
fmla =
|
|
1627 |
try_dest_Trueprop fmla
|
|
1628 |
|> remove_repeated_quantification []
|
|
1629 |
|> fst
|
|
1630 |
|> HOLogic.mk_Trueprop,
|
|
1631 |
source_inf_opt = source_inf_opt})
|
|
1632 |
in
|
|
1633 |
(thy, map remove_repeated_quantification' fms)
|
|
1634 |
end
|
|
1635 |
|
|
1636 |
|
|
1637 |
(** Proof transformer to detect a redundant splitting and remove
|
|
1638 |
the redundant branch. **)
|
|
1639 |
|
|
1640 |
fun node_is_inference fms rule_name node_name =
|
|
1641 |
case node_info fms #source_inf_opt node_name of
|
|
1642 |
NONE => false
|
|
1643 |
| SOME (TPTP_Proof.File _) => false
|
|
1644 |
| SOME (TPTP_Proof.Inference (rule_name', _, _)) => rule_name' = rule_name
|
|
1645 |
|
|
1646 |
(*In this analysis we're interested if there exists a split-free
|
|
1647 |
path between the end of the proof and the negated conjecture.
|
|
1648 |
If so, then this path (or the shortest such path) could be
|
|
1649 |
retained, and the rest of the proof erased.*)
|
|
1650 |
datatype branch_info =
|
|
1651 |
Split_free (*Path is not part of a split. This is only used when path reaches the negated conjecture.*)
|
|
1652 |
| Split_present (*Path is one of a number of splits. Such paths are excluded.*)
|
|
1653 |
| Coinconsistent of int (*Path leads to a clause which is inconsistent with nodes concluded by other paths.
|
|
1654 |
Therefore this path should be kept if the others are kept
|
|
1655 |
(i.e., unless one of them results from a split)*)
|
|
1656 |
| No_info (*Analysis hasn't come across anything definite yet, though it still hasn't completed.*)
|
|
1657 |
(*A "paths" value consist of every way of reaching the destination,
|
|
1658 |
including information come across it so far. Taking the head of
|
|
1659 |
each way gives the fringe. All paths should share the same source
|
|
1660 |
and sink.*)
|
|
1661 |
type path = (branch_info * string list)
|
|
1662 |
exception PRUNE_REDUNDANT_SPLITS
|
|
1663 |
fun prune_redundant_splits prob_name thy fms : theory * formula_meaning list =
|
|
1664 |
let
|
|
1665 |
(*All paths start at the contradiction*)
|
|
1666 |
val initial_path = (No_info, [proof_end_node fms])
|
|
1667 |
(*All paths should end at the proof's beginning*)
|
|
1668 |
val end_node = proof_beginning_node fms
|
|
1669 |
|
|
1670 |
fun compute_path (path as ((info,
|
|
1671 |
(n :: ns)) : path))(*i.e. node list can't be empty*)
|
|
1672 |
intermediate_thy =
|
|
1673 |
case info of
|
|
1674 |
Split_free => (([path], []), intermediate_thy)
|
|
1675 |
| Coinconsistent branch_id =>
|
|
1676 |
(*If this branch has a split_conjecture parent then all "sibling" branches get erased.*)
|
|
1677 |
(*This branch can't lead to yet another coinconsistent branch (in the case of Leo2).*)
|
|
1678 |
let
|
|
1679 |
val parent_nodes = parents_of_node fms n
|
|
1680 |
in
|
|
1681 |
if List.exists (node_is_inference fms "split_conjecture") parent_nodes then
|
|
1682 |
(([], [branch_id]), intermediate_thy) (*all related branches are to be deleted*)
|
|
1683 |
else
|
|
1684 |
list_prod [] parent_nodes (n :: ns)
|
|
1685 |
|> map (fn ns' => (Coinconsistent branch_id, ns'))
|
|
1686 |
|> (fn x => ((x, []), intermediate_thy))
|
|
1687 |
end
|
|
1688 |
|
|
1689 |
| No_info =>
|
|
1690 |
let
|
|
1691 |
val parent_nodes = parents_of_node fms n
|
|
1692 |
|
|
1693 |
(*if this node is a consistency checking node then parent nodes will be marked as coinconsistent*)
|
|
1694 |
val (thy', new_branch_info) =
|
|
1695 |
if node_is_inference fms "fo_atp_e" n orelse
|
|
1696 |
node_is_inference fms "res" n then
|
|
1697 |
let
|
|
1698 |
val (i', intermediate_thy') = get_next_int intermediate_thy
|
|
1699 |
in
|
|
1700 |
(intermediate_thy', SOME (Coinconsistent i'))
|
|
1701 |
end
|
|
1702 |
else (intermediate_thy, NONE)
|
|
1703 |
in
|
|
1704 |
if List.exists (node_is_inference fms "split_conjecture") parent_nodes then
|
|
1705 |
(([], []), thy')
|
|
1706 |
else
|
|
1707 |
list_prod [] parent_nodes (n :: ns)
|
|
1708 |
|> map (fn ns' =>
|
|
1709 |
let
|
|
1710 |
val info =
|
|
1711 |
if is_some new_branch_info then the new_branch_info
|
|
1712 |
else
|
|
1713 |
if hd ns' = end_node then Split_free else No_info
|
|
1714 |
in (info, ns') end)
|
|
1715 |
|> (fn x => ((x, []), thy'))
|
|
1716 |
end
|
|
1717 |
| _ => raise PRUNE_REDUNDANT_SPLITS
|
|
1718 |
|
|
1719 |
fun compute_paths intermediate_thy (paths : path list) =
|
|
1720 |
if filter (fn (_, ns) => ns <> [] andalso hd ns = end_node) paths = paths then
|
|
1721 |
(*fixpoint reached when all paths are at the head position*)
|
|
1722 |
(intermediate_thy, paths)
|
|
1723 |
else
|
|
1724 |
let
|
|
1725 |
val filtered_paths = filter (fn (info, _) : path => info <> Split_present) paths (*not interested in paths containing a split*)
|
|
1726 |
val (paths', thy') =
|
|
1727 |
fold_map compute_path filtered_paths intermediate_thy
|
|
1728 |
in
|
|
1729 |
paths'
|
|
1730 |
|> ListPair.unzip (*we get a list of pairs of lists. we want a pair of lists*)
|
|
1731 |
|> (fn (paths, branch_ids) =>
|
|
1732 |
(List.concat paths,
|
|
1733 |
(*remove duplicate branch_ids*)
|
|
1734 |
fold (Library.insert (op =)) (List.concat branch_ids) []))
|
|
1735 |
(*filter paths having branch_ids appearing in the second list*)
|
|
1736 |
|> (fn (paths, branch_ids) =>
|
|
1737 |
filter (fn (info, _) =>
|
|
1738 |
case info of
|
|
1739 |
Coinconsistent branch_id => List.exists (fn x => x = branch_id) branch_ids
|
|
1740 |
| _ => true) paths)
|
|
1741 |
|> compute_paths thy'
|
|
1742 |
end
|
|
1743 |
|
|
1744 |
val (thy', paths) =
|
|
1745 |
compute_paths thy [initial_path]
|
|
1746 |
|> apsnd
|
|
1747 |
(filter (fn (branch_info, _) =>
|
|
1748 |
case branch_info of
|
|
1749 |
Split_free => true
|
|
1750 |
| Coinconsistent _ => true
|
|
1751 |
| _ => false))
|
|
1752 |
(*Extract subset of fms which is used in a path.
|
|
1753 |
Also, remove references (in parent info annotations) to erased nodes.*)
|
|
1754 |
fun path_to_fms ((_, nodes) : path) =
|
|
1755 |
fold
|
|
1756 |
(fn n => fn fms' =>
|
|
1757 |
case AList.lookup (op =) fms' n of
|
|
1758 |
SOME _ => fms'
|
|
1759 |
| NONE =>
|
|
1760 |
let
|
|
1761 |
val node_info = the (AList.lookup (op =) fms n)
|
|
1762 |
|
|
1763 |
val source_info' =
|
|
1764 |
case #source_inf_opt node_info of
|
|
1765 |
NONE => error "Only the conjecture is an orphan"
|
|
1766 |
| SOME (source_info as TPTP_Proof.File _) => source_info
|
|
1767 |
| SOME (source_info as
|
|
1768 |
TPTP_Proof.Inference (inference_name,
|
|
1769 |
useful_infos : TPTP_Proof.useful_info_as list,
|
|
1770 |
parent_infos)) =>
|
|
1771 |
let
|
|
1772 |
fun is_node_in_fms' parent_info =
|
|
1773 |
let
|
|
1774 |
val parent_nodename =
|
|
1775 |
case parent_info of
|
|
1776 |
TPTP_Proof.Parent n => n
|
|
1777 |
| TPTP_Proof.ParentWithDetails (n, _) => n
|
|
1778 |
in
|
|
1779 |
case AList.lookup (op =) fms' parent_nodename of
|
|
1780 |
NONE => false
|
|
1781 |
| SOME _ => true
|
|
1782 |
end
|
|
1783 |
in
|
|
1784 |
TPTP_Proof.Inference (inference_name,
|
|
1785 |
useful_infos,
|
|
1786 |
filter is_node_in_fms' parent_infos)
|
|
1787 |
end
|
|
1788 |
in
|
|
1789 |
(n,
|
|
1790 |
{role = #role node_info,
|
|
1791 |
fmla = #fmla node_info,
|
|
1792 |
source_inf_opt = SOME source_info'}) :: fms'
|
|
1793 |
end)
|
|
1794 |
nodes
|
|
1795 |
[]
|
|
1796 |
in
|
|
1797 |
if null paths then (thy', fms) else
|
|
1798 |
(thy',
|
|
1799 |
hd(*FIXME could pick path based on length, or some notion of "difficulty"*) paths
|
|
1800 |
|> path_to_fms)
|
|
1801 |
end
|
|
1802 |
|
|
1803 |
|
|
1804 |
(*** Main functions ***)
|
|
1805 |
|
|
1806 |
(*interpret proof*)
|
|
1807 |
fun import_thm cautious path_prefixes file_name
|
|
1808 |
(on_load : proof_annotation -> theory -> (proof_annotation * theory)) thy =
|
|
1809 |
let
|
|
1810 |
val prob_name =
|
|
1811 |
Path.base file_name
|
|
1812 |
|> Path.implode
|
|
1813 |
|> TPTP_Problem_Name.parse_problem_name
|
|
1814 |
val thy1 = TPTP_Interpret.import_file cautious path_prefixes file_name [] [] thy
|
|
1815 |
val fms = get_fmlas_of_prob thy1 prob_name
|
|
1816 |
in
|
|
1817 |
if List.null fms then
|
|
1818 |
(warning ("File " ^ Path.implode file_name ^ " appears empty!");
|
|
1819 |
TPTP_Reconstruction_Data.map (cons ((prob_name, empty_pannot prob_name))) thy1)
|
|
1820 |
else
|
|
1821 |
let
|
|
1822 |
val defn_equations =
|
|
1823 |
List.filter (fn (_, role, _, _) => role = TPTP_Syntax.Role_Definition) fms
|
|
1824 |
|> map (fn (node, _, t, _) =>
|
|
1825 |
(node,
|
|
1826 |
get_defn_components t
|
|
1827 |
|> mk_bind_eq prob_name []))
|
|
1828 |
val axioms =
|
|
1829 |
List.filter (fn (_, role, _, _) => role = TPTP_Syntax.Role_Axiom) fms
|
|
1830 |
|> map (fn (node, _, t, _) =>
|
|
1831 |
(node,
|
|
1832 |
mk_bind_ax prob_name node t))
|
|
1833 |
|
|
1834 |
(*add definitions and axioms to the theory*)
|
|
1835 |
val thy2 =
|
|
1836 |
fold
|
|
1837 |
(fn bnd => fn thy =>
|
|
1838 |
let
|
|
1839 |
val ((name, thm), thy') = Thm.add_axiom_global bnd thy
|
|
1840 |
in Global_Theory.add_thm ((#1 bnd, thm), []) thy' |> #2 end)
|
|
1841 |
(map snd defn_equations @ map snd axioms)
|
|
1842 |
thy1
|
|
1843 |
|
|
1844 |
(*apply global proof transformations*)
|
|
1845 |
val (thy3, pre_pannot) : theory * proof_annotation =
|
|
1846 |
transf_pannot
|
|
1847 |
(prune_redundant_splits prob_name thy2
|
|
1848 |
#-> interpolate_binds prob_name
|
|
1849 |
#-> preprocess_splits prob_name
|
|
1850 |
#-> drop_repeated_quantification)
|
|
1851 |
{problem_name = prob_name,
|
|
1852 |
skolem_defs = [],
|
|
1853 |
defs = map (apsnd fst) defn_equations,
|
|
1854 |
axs = map (apsnd fst) axioms,
|
|
1855 |
meta = map (fn (n, r, t, info) => (n, {role=r, fmla=t, source_inf_opt=info})) fms}
|
|
1856 |
|
|
1857 |
(*store pannot*)
|
|
1858 |
val thy4 = TPTP_Reconstruction_Data.map (cons ((prob_name, pre_pannot))) thy3
|
|
1859 |
|
|
1860 |
(*run hook, which might result in changed pannot and theory*)
|
|
1861 |
val (pannot, thy5) = on_load pre_pannot thy4
|
|
1862 |
|
|
1863 |
(*store the most recent pannot*)
|
|
1864 |
in TPTP_Reconstruction_Data.map (cons ((prob_name, pannot))) thy5 end
|
|
1865 |
end
|
|
1866 |
|
|
1867 |
(*This has been disabled since it requires a hook to be specified to use "import_thm"
|
|
1868 |
val _ =
|
|
1869 |
Outer_Syntax.improper_command @{command_spec "import_leo2_proof"} "import TPTP proof"
|
|
1870 |
(Parse.path >> (fn name =>
|
|
1871 |
Toplevel.theory (fn thy =>
|
|
1872 |
let val path = Path.explode name
|
|
1873 |
in import_thm true [Path.dir path, Path.explode "$TPTP"] path (*FIXME hook needs to be given here*)
|
|
1874 |
thy end)))
|
|
1875 |
*)
|
|
1876 |
|
|
1877 |
|
|
1878 |
(** Archive **)
|
|
1879 |
(*FIXME move elsewhere*)
|
|
1880 |
(*This contains currently unused, but possibly useful, functions written
|
|
1881 |
during experimentation, in case they are useful later on*)
|
|
1882 |
|
|
1883 |
(*given a list of rules and a node, return
|
|
1884 |
SOME (rule name) if that node's rule name
|
|
1885 |
belongs to the list of rules*)
|
|
1886 |
fun match_rules_of_current (pannot : proof_annotation) rules n =
|
|
1887 |
case node_info (#meta pannot) #source_inf_opt n of
|
|
1888 |
NONE => NONE
|
|
1889 |
| SOME (TPTP_Proof.File _) => NONE
|
|
1890 |
| SOME (TPTP_Proof.Inference (rule_name, _ : TPTP_Proof.useful_info_as list, _)) =>
|
|
1891 |
if member (op =) rules rule_name then SOME rule_name else NONE
|
|
1892 |
|
|
1893 |
(*given a node and a list of rules, determine
|
|
1894 |
whether all the rules can be matched to
|
|
1895 |
parent nodes. If nonstrict then there may be
|
|
1896 |
more parents than given rules.*)
|
|
1897 |
fun match_rules_of_immediate_previous (pannot : proof_annotation) strict rules n =
|
|
1898 |
case node_info (#meta pannot) #source_inf_opt n of
|
|
1899 |
NONE => null rules
|
|
1900 |
| SOME (TPTP_Proof.File _) => null rules
|
|
1901 |
| SOME (TPTP_Proof.Inference (rule_name, _ : TPTP_Proof.useful_info_as list, parent_infos)) =>
|
|
1902 |
let
|
|
1903 |
val matched_rules : string option list =
|
|
1904 |
map (match_rules_of_current pannot rules)
|
|
1905 |
(dest_parent_infos true (#meta pannot) parent_infos |> map #name)
|
|
1906 |
in
|
|
1907 |
if strict andalso member (op =) matched_rules NONE then false
|
|
1908 |
else
|
|
1909 |
(*check that all the rules were matched*)
|
|
1910 |
fold
|
|
1911 |
(fn (rule : string) => fn (st, matches : string option list) =>
|
|
1912 |
if not st then (st, matches)
|
|
1913 |
else
|
|
1914 |
let
|
|
1915 |
val idx = find_index (fn match => SOME rule = match) matches
|
|
1916 |
in
|
|
1917 |
if idx < 0 then (false, matches)
|
|
1918 |
else
|
|
1919 |
(st, nth_drop idx matches)
|
|
1920 |
end)
|
|
1921 |
rules
|
|
1922 |
(true, matched_rules)
|
|
1923 |
|> #1 (*discard the other info*)
|
|
1924 |
end
|
|
1925 |
end
|