1 (* ID: $Id$ |
1 (* ID: $Id$ |
2 Author: Claire Quigley and L C Paulson |
2 Author: L C Paulson and Claire Quigley |
3 Copyright 2004 University of Cambridge |
3 Copyright 2004 University of Cambridge |
4 *) |
4 *) |
5 |
5 |
|
6 (*FIXME: can we delete the "thm * int" and "th sgno" below?*) |
|
7 |
6 (***************************************************************************) |
8 (***************************************************************************) |
7 (* Code to deal with the transfer of proofs from a Vampire process *) |
9 (* Code to deal with the transfer of proofs from a prover process *) |
8 (***************************************************************************) |
10 (***************************************************************************) |
9 signature RES_RECONSTRUCT = |
11 signature RES_RECONSTRUCT = |
10 sig |
12 sig |
11 val checkEProofFound: |
13 val checkEProofFound: |
12 TextIO.instream * TextIO.outstream * Posix.Process.pid * |
14 TextIO.instream * TextIO.outstream * Posix.Process.pid * |
277 end; |
279 end; |
278 |
280 |
279 (*Quantification over a list of Vars. FUXNE: for term.ML??*) |
281 (*Quantification over a list of Vars. FUXNE: for term.ML??*) |
280 fun list_all_var ([], t: term) = t |
282 fun list_all_var ([], t: term) = t |
281 | list_all_var ((v as Var(ix,T)) :: vars, t) = |
283 | list_all_var ((v as Var(ix,T)) :: vars, t) = |
282 (all T) $ Abs(string_of_indexname ix, T, abstract_over (v,t)); |
284 (all T) $ Abs(string_of_indexname ix, T, abstract_over (v, list_all_var (vars,t))); |
283 |
285 |
284 fun gen_all_vars t = list_all_var (term_vars t, t); |
286 fun gen_all_vars t = list_all_var (term_vars t, t); |
285 |
287 |
286 fun clause_of_strees thy vt0 ts = |
288 fun clause_of_strees thy vt0 ts = |
287 gen_all_vars (HOLogic.mk_Trueprop (clause_of_strees_aux thy vt0 ts)); |
289 gen_all_vars (HOLogic.mk_Trueprop (clause_of_strees_aux thy vt0 ts)); |
365 (*Replace numeric proof lines by strings.*) |
367 (*Replace numeric proof lines by strings.*) |
366 fun stringify_deps thm_names deps_map [] = [] |
368 fun stringify_deps thm_names deps_map [] = [] |
367 | stringify_deps thm_names deps_map ((lno, t, deps) :: lines) = |
369 | stringify_deps thm_names deps_map ((lno, t, deps) :: lines) = |
368 if lno <= Vector.length thm_names (*axiom*) |
370 if lno <= Vector.length thm_names (*axiom*) |
369 then (Vector.sub(thm_names,lno-1), t, []) :: stringify_deps thm_names deps_map lines |
371 then (Vector.sub(thm_names,lno-1), t, []) :: stringify_deps thm_names deps_map lines |
370 else let val lname = "L" ^ Int.toString (length deps_map) |
372 else let val lname = Int.toString (length deps_map) |
371 fun fix lno = if lno <= Vector.length thm_names |
373 fun fix lno = if lno <= Vector.length thm_names |
372 then SOME(Vector.sub(thm_names,lno-1)) |
374 then SOME(Vector.sub(thm_names,lno-1)) |
373 else AList.lookup op= deps_map lno; |
375 else AList.lookup op= deps_map lno; |
374 in (lname, t, List.mapPartial fix deps) :: |
376 in (lname, t, List.mapPartial fix deps) :: |
375 stringify_deps thm_names ((lno,lname)::deps_map) lines |
377 stringify_deps thm_names ((lno,lname)::deps_map) lines |
376 end; |
378 end; |
377 |
379 |
|
380 val proofstart = "\nproof (rule ccontr, skolemize, make_clauses)\n"; |
|
381 |
|
382 fun string_of_Free (Free (x,_)) = x |
|
383 | string_of_Free _ = "??string_of_Free??"; |
|
384 |
|
385 fun isar_header [] = proofstart |
|
386 | isar_header ts = proofstart ^ "fix " ^ space_implode " " (map string_of_Free ts) ^ "\n"; |
|
387 |
378 fun decode_tstp_file ctxt (cnfs,thm_names) = |
388 fun decode_tstp_file ctxt (cnfs,thm_names) = |
379 let val tuples = map (dest_tstp o tstp_line o explode) cnfs |
389 let val tuples = map (dest_tstp o tstp_line o explode) cnfs |
380 val lines = foldr add_prfline [] (decode_tstp_list (ProofContext.theory_of ctxt) tuples) |
390 val decoded_tuples = decode_tstp_list (ProofContext.theory_of ctxt) tuples |
381 in String.concat (isar_lines ctxt (stringify_deps thm_names [] lines)) end; |
391 val lines = foldr add_prfline [] decoded_tuples |
|
392 and fixes = foldr add_term_frees [] (map #3 decoded_tuples) |
|
393 in |
|
394 isar_header fixes ^ |
|
395 String.concat (isar_lines ctxt (stringify_deps thm_names [] lines)) |
|
396 end; |
382 |
397 |
383 (*Could use split_lines, but it can return blank lines...*) |
398 (*Could use split_lines, but it can return blank lines...*) |
384 val lines = String.tokens (equal #"\n"); |
399 val lines = String.tokens (equal #"\n"); |
385 |
400 |
386 val nospaces = String.translate (fn c => if Char.isSpace c then "" else str c); |
401 val nospaces = String.translate (fn c => if Char.isSpace c then "" else str c); |