src/HOL/Tools/ATP/AtpCommunication.ML
author wenzelm
Sat, 17 Dec 2005 01:00:40 +0100
changeset 18428 4059413acbc1
parent 17773 a7258e1020b7
child 18700 f04a8755d6ca
permissions -rw-r--r--
sort_distinct;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     1
(*  Title:      VampCommunication.ml
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     2
    ID:         $Id$
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     3
    Author:     Claire Quigley
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     4
    Copyright   2004  University of Cambridge
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     5
*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     6
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     7
(***************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     8
(*  Code to deal with the transfer of proofs from a Vampire process          *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
     9
(***************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    10
signature ATP_COMMUNICATION =
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    11
  sig
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    12
    val reconstruct : bool ref
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    13
    val checkEProofFound: 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    14
          TextIO.instream * TextIO.outstream * Posix.Process.pid * 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    15
          string * (ResClause.clause * thm) Array.array -> bool
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    16
    val checkVampProofFound: 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    17
          TextIO.instream * TextIO.outstream * Posix.Process.pid * 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    18
          string * (ResClause.clause * thm) Array.array -> bool
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    19
    val checkSpassProofFound:  
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    20
          TextIO.instream * TextIO.outstream * Posix.Process.pid * 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    21
          string * thm * int * (ResClause.clause * thm) Array.array -> bool
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
    22
    val signal_parent:  
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
    23
          TextIO.outstream * Posix.Process.pid * string * string -> unit
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    24
  end;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    25
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    26
structure AtpCommunication : ATP_COMMUNICATION =
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    27
struct
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    28
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    29
(* switch for whether to reconstruct a proof found, or just list the lemmas used *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    30
val reconstruct = ref false;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    31
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    32
val trace_path = Path.basic "atp_trace";
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    33
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    34
fun trace s = if !Output.show_debug_msgs then File.append (File.tmp_path trace_path) s 
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    35
              else ();
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    36
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    37
exception EOF;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    38
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    39
val start_E = "# Proof object starts here."
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    40
val end_E   = "# Proof object ends here."
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    41
val start_V6 = "%================== Proof: ======================"
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    42
val end_V6   = "%==============  End of proof. =================="
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    43
val start_V8 = "=========== Refutation =========="
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    44
val end_V8 = "======= End of refutation ======="
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    45
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    46
(*Identifies the start/end lines of an ATP's output*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    47
local open Recon_Parse in
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    48
fun extract_proof s =
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    49
  if cut_exists "Here is a proof with" s then
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    50
    (kill_lines 0
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    51
     o snd o cut_after ":"
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    52
     o snd o cut_after "Here is a proof with"
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    53
     o fst o cut_after " ||  -> .") s
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    54
  else if cut_exists end_V8 s then
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    55
    (kill_lines 0    (*Vampire 8.0*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    56
     o fst o cut_before end_V8) s
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    57
  else if cut_exists end_E s then
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    58
    (kill_lines 0    (*eproof*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    59
     o fst o cut_before end_E) s
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    60
  else "??extract_proof failed" (*Couldn't find a proof*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    61
end;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    62
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    63
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    64
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    65
(*  Inspect the output of an ATP process to see if it has found a proof,     *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    66
(*  and if so, transfer output to the input pipe of the main Isabelle process    *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    67
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    68
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    69
fun startTransfer (endS, fromChild, toParent, ppid, probfile, clause_arr) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    70
 let fun transferInput currentString =
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    71
      let val thisLine = TextIO.inputLine fromChild
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    72
      in
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    73
	if thisLine = "" (*end of file?*)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    74
	then (trace ("\n extraction_failed.  End bracket: " ^ endS ^
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    75
	             "\naccumulated text: " ^ currentString);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    76
	      raise EOF)                    
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    77
	else if String.isPrefix endS thisLine
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    78
	then let val proofextract = extract_proof (currentString^thisLine)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    79
	         val lemma_list = if endS = end_V8 
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    80
			  	  then Recon_Transfer.vamp_lemma_list
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    81
			  	  else Recon_Transfer.e_lemma_list
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    82
	     in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    83
	       trace ("\nExtracted proof:\n" ^ proofextract); 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    84
	       lemma_list proofextract probfile toParent ppid clause_arr
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    85
	     end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    86
	else transferInput (currentString^thisLine)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    87
      end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    88
 in
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    89
     transferInput "";  true
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    90
 end handle EOF => false
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    91
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    92
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    93
(*The signal handler in watcher.ML must be able to read the output of this.*)
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    94
fun signal_parent (toParent, ppid, msg, probfile) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    95
 (TextIO.output (toParent, msg);
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    96
  TextIO.output (toParent, probfile ^ "\n");
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    97
  TextIO.flushOut toParent;
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    98
  trace ("\nSignalled parent: " ^ msg ^ probfile);
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
    99
  Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   100
  (*Give the parent time to respond before possibly sending another signal*)
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   101
  OS.Process.sleep (Time.fromMilliseconds 600));
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   102
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   103
(*Called from watcher. Returns true if the Vampire process has returned a verdict.*)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   104
fun checkVampProofFound (fromChild, toParent, ppid, probfile, clause_arr) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   105
 let val thisLine = TextIO.inputLine fromChild
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   106
 in   
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   107
     trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   108
     if thisLine = "" 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   109
     then (trace "\nNo proof output seen"; false)
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   110
     else if String.isPrefix start_V8 thisLine
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   111
     then startTransfer (end_V8, fromChild, toParent, ppid, probfile, clause_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   112
     else if (String.isPrefix "Satisfiability detected" thisLine) orelse
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   113
             (String.isPrefix "Refutation not found" thisLine)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   114
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   115
	   true)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   116
     else
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   117
        checkVampProofFound  (fromChild, toParent, ppid, probfile, clause_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   118
  end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   119
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   120
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   121
(*Called from watcher. Returns true if the E process has returned a verdict.*)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   122
fun checkEProofFound (fromChild, toParent, ppid, probfile, clause_arr) = 
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   123
 let val thisLine = TextIO.inputLine fromChild  
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   124
 in   
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   125
     trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   126
     if thisLine = "" 
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   127
     then (trace "\nNo proof output seen"; false)
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   128
     else if String.isPrefix start_E thisLine
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   129
     then      
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   130
       startTransfer (end_E, fromChild, toParent, ppid, probfile, clause_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   131
     else if String.isPrefix "# Problem is satisfiable" thisLine
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   132
     then (signal_parent (toParent, ppid, "Invalid\n", probfile);
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   133
	   true)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   134
     else if String.isPrefix "# Cannot determine problem status within resource limit" thisLine
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   135
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
17690
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   136
	   true)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   137
     else
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   138
	checkEProofFound (fromChild, toParent, ppid, probfile, clause_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   139
 end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   140
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   141
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   142
(**********************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   143
(*  Reconstruct the Spass proof w.r.t. thmstring (string version of   *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   144
(*  Isabelle goal to be proved), then transfer the reconstruction     *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   145
(*  steps as a string to the input pipe of the main Isabelle process  *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   146
(**********************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   147
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   148
fun spass_reconstruct_tac proofextract toParent ppid probfile sg_num clause_arr = 
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   149
 SELECT_GOAL
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17488
diff changeset
   150
  (EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, 
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   151
	   METAHYPS(fn negs => 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   152
		  Recon_Transfer.spass_reconstruct proofextract probfile 
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   153
				toParent ppid negs clause_arr)]) sg_num;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   154
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   155
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   156
fun transferSpassInput (fromChild, toParent, ppid, probfile,
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   157
                        currentString, thm, sg_num, clause_arr) = 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   158
 let val thisLine = TextIO.inputLine fromChild 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   159
 in 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   160
    trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   161
    if thisLine = "" (*end of file?*)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   162
    then (trace ("\nspass_extraction_failed: " ^ currentString);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   163
	  raise EOF)                    
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   164
    else if String.isPrefix "--------------------------SPASS-STOP" thisLine
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   165
    then 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   166
      let val proofextract = extract_proof (currentString^thisLine)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   167
      in 
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   168
	 trace ("\nextracted spass proof: " ^ proofextract);
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   169
	 if !reconstruct 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   170
	 then (spass_reconstruct_tac proofextract toParent ppid probfile sg_num 
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   171
		clause_arr thm; ())
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   172
	 else Recon_Transfer.spass_lemma_list proofextract probfile toParent
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   173
	        ppid clause_arr 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   174
      end
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   175
    else transferSpassInput (fromChild, toParent, ppid, probfile,
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   176
			     (currentString^thisLine), thm, sg_num, clause_arr)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   177
 end;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   178
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   179
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   180
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   181
(*  Inspect the output of a Spass   process to see if it has found a proof,     *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   182
(*  and if so, transfer output to the input pipe of the main Isabelle process    *)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   183
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   184
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   185
 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   186
fun startSpassTransfer (fromChild, toParent, ppid, probfile,
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   187
                        thm, sg_num,clause_arr) = 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   188
   let val thisLine = TextIO.inputLine fromChild  
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   189
   in                 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   190
      if thisLine = "" then false
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   191
      else if String.isPrefix "Here is a proof" thisLine then     
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   192
	 (trace ("\nabout to transfer SPASS proof\n:");
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   193
	  transferSpassInput (fromChild, toParent, ppid, probfile, thisLine, 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   194
 	                     thm, sg_num,clause_arr);
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   195
	  true) handle EOF => false
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   196
      else startSpassTransfer (fromChild, toParent, ppid, probfile, thm, sg_num,clause_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   197
    end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   198
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   199
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   200
(*Called from watcher. Returns true if the SPASS process has returned a verdict.*)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   201
fun checkSpassProofFound (fromChild, toParent, ppid, probfile,
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   202
                          thm, sg_num, clause_arr) = 
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   203
 let val thisLine = TextIO.inputLine fromChild  
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   204
 in    
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   205
     trace thisLine;
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   206
     if thisLine = "" then (trace "\nNo proof output seen"; false)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   207
     else if thisLine = "SPASS beiseite: Proof found.\n"
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   208
     then      
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   209
        startSpassTransfer (fromChild, toParent, ppid, probfile, thm, sg_num, clause_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   210
     else if thisLine = "SPASS beiseite: Completion found.\n"
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   211
     then (signal_parent (toParent, ppid, "Invalid\n", probfile);
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   212
	   true)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   213
     else if thisLine = "SPASS beiseite: Ran out of time.\n" orelse
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   214
             thisLine = "SPASS beiseite: Maximal number of loops exceeded.\n"
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   215
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   216
	   true)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   217
    else checkSpassProofFound (fromChild, toParent, ppid, probfile, thm, sg_num, clause_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   218
 end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   219
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   220
end;