src/HOL/Tools/ATP/AtpCommunication.ML
author wenzelm
Tue, 11 Jul 2006 12:17:08 +0200
changeset 20083 717b1eb434f1
parent 19199 b338c218cc6e
child 20762 a7a5157c5e75
permissions -rw-r--r--
removed obsolete mem_ix;
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 * 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    15
          string * string 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 * 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    18
          string * string 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 * 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    21
          string * thm * int * string 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 =
18700
f04a8755d6ca improved SPASS support
paulson
parents: 17773
diff changeset
    49
  if cut_exists "Formulae used in the proof" s then  (*SPASS*)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    50
    (kill_lines 0
18700
f04a8755d6ca improved SPASS support
paulson
parents: 17773
diff changeset
    51
     o fst o cut_before "Formulae used in the proof") s
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    52
  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
    53
    (kill_lines 0    (*Vampire 8.0*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    54
     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
    55
  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
    56
    (kill_lines 0    (*eproof*)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    57
     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
    58
  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
    59
end;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    60
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    61
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
(*  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
    64
(*  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
    65
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    66
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    67
fun startTransfer (endS, fromChild, toParent, ppid, probfile, names_arr) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    68
 let fun transferInput currentString =
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    69
      let val thisLine = TextIO.inputLine fromChild
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    70
      in
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    71
	if thisLine = "" (*end of file?*)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    72
	then (trace ("\n extraction_failed.  End bracket: " ^ endS ^
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    73
	             "\naccumulated text: " ^ currentString);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    74
	      raise EOF)                    
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    75
	else if String.isPrefix endS thisLine
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    76
	then let val proofextract = extract_proof (currentString^thisLine)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    77
	         val lemma_list = if endS = end_V8 
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    78
			  	  then Recon_Transfer.vamp_lemma_list
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    79
			  	  else Recon_Transfer.e_lemma_list
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    80
	     in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    81
	       trace ("\nExtracted proof:\n" ^ proofextract); 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    82
	       lemma_list proofextract probfile toParent ppid names_arr
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    83
	     end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    84
	else transferInput (currentString^thisLine)
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
 in
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    87
     transferInput "";  true
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    88
 end handle EOF => false
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    89
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    90
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    91
(*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
    92
fun signal_parent (toParent, ppid, msg, probfile) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    93
 (TextIO.output (toParent, msg);
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    94
  TextIO.output (toParent, probfile ^ "\n");
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
    95
  TextIO.flushOut toParent;
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
    96
  trace ("\nSignalled parent: " ^ msg ^ probfile);
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
    97
  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
    98
  (*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
    99
  OS.Process.sleep (Time.fromMilliseconds 600));
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   100
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   101
(*Called from watcher. Returns true if the Vampire process has returned a verdict.*)
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   102
fun checkVampProofFound (fromChild, toParent, ppid, probfile, names_arr) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   103
 let val thisLine = TextIO.inputLine fromChild
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   104
 in   
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   105
     trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   106
     if thisLine = "" 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   107
     then (trace "\nNo proof output seen"; false)
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   108
     else if String.isPrefix start_V8 thisLine
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   109
     then startTransfer (end_V8, fromChild, toParent, ppid, probfile, names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   110
     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
   111
             (String.isPrefix "Refutation not found" thisLine)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   112
     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
   113
	   true)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   114
     else
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   115
        checkVampProofFound  (fromChild, toParent, ppid, probfile, names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   116
  end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   117
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   118
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   119
(*Called from watcher. Returns true if the E process has returned a verdict.*)
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   120
fun checkEProofFound (fromChild, toParent, ppid, probfile, names_arr) = 
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   121
 let val thisLine = TextIO.inputLine fromChild  
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   122
 in   
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   123
     trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   124
     if thisLine = "" 
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   125
     then (trace "\nNo proof output seen"; false)
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   126
     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
   127
     then      
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   128
       startTransfer (end_E, fromChild, toParent, ppid, probfile, names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   129
     else if String.isPrefix "# Problem is satisfiable" thisLine
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   130
     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
   131
	   true)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   132
     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
   133
     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
   134
	   true)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   135
     else
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   136
	checkEProofFound (fromChild, toParent, ppid, probfile, names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   137
 end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   138
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   139
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
(*  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
   142
(*  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
   143
(*  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
   144
(**********************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   145
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   146
fun spass_reconstruct_tac proofextract toParent ppid probfile sg_num names_arr = 
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   147
 SELECT_GOAL
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17488
diff changeset
   148
  (EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, 
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   149
	   METAHYPS(fn negs => 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   150
		  Recon_Transfer.spass_reconstruct proofextract probfile 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   151
				toParent ppid negs names_arr)]) sg_num;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   152
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   153
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   154
fun transferSpassInput (fromChild, toParent, ppid, probfile,
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   155
                        currentString, thm, sg_num, names_arr) = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   156
 let val thisLine = TextIO.inputLine fromChild 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   157
 in 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   158
    trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   159
    if thisLine = "" (*end of file?*)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   160
    then (trace ("\nspass_extraction_failed: " ^ currentString);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   161
	  raise EOF)                    
18700
f04a8755d6ca improved SPASS support
paulson
parents: 17773
diff changeset
   162
    else if String.isPrefix "Formulae used in the proof" thisLine
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   163
    then 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   164
      let val proofextract = extract_proof (currentString^thisLine)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   165
      in 
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   166
	 trace ("\nextracted spass proof: " ^ proofextract);
17488
67376a311a2b further simplification of the Isabelle-ATP linkup
paulson
parents: 17484
diff changeset
   167
	 if !reconstruct 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   168
	 then (spass_reconstruct_tac proofextract toParent ppid probfile sg_num 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   169
		names_arr thm; ())
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   170
	 else Recon_Transfer.spass_lemma_list proofextract probfile toParent
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   171
	        ppid names_arr 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   172
      end
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   173
    else transferSpassInput (fromChild, toParent, ppid, probfile,
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   174
			     (currentString^thisLine), thm, sg_num, names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   175
 end;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   176
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   177
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
(*  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
   180
(*  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
   181
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   182
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   183
 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   184
fun startSpassTransfer (fromChild, toParent, ppid, probfile,
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   185
                        thm, sg_num,names_arr) = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   186
   let val thisLine = TextIO.inputLine fromChild  
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   187
   in                 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   188
      if thisLine = "" then false
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   189
      else if String.isPrefix "Here is a proof" thisLine then     
18700
f04a8755d6ca improved SPASS support
paulson
parents: 17773
diff changeset
   190
	 (trace ("\nabout to transfer SPASS proof:\n");
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   191
	  transferSpassInput (fromChild, toParent, ppid, probfile, thisLine, 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   192
 	                     thm, sg_num,names_arr);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   193
	  true) handle EOF => false
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   194
      else startSpassTransfer (fromChild, toParent, ppid, probfile, thm, sg_num,names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   195
    end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   196
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   197
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   198
(*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
   199
fun checkSpassProofFound (fromChild, toParent, ppid, probfile,
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   200
                          thm, sg_num, names_arr) = 
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   201
 let val thisLine = TextIO.inputLine fromChild  
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   202
 in    
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   203
     trace thisLine;
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   204
     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
   205
     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
   206
     then      
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   207
        startSpassTransfer (fromChild, toParent, ppid, probfile, thm, sg_num, names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   208
     else if thisLine = "SPASS beiseite: Completion found.\n"
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   209
     then (signal_parent (toParent, ppid, "Invalid\n", probfile);
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   210
	   true)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   211
     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
   212
             thisLine = "SPASS beiseite: Maximal number of loops exceeded.\n"
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   213
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   214
	   true)
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   215
    else checkSpassProofFound (fromChild, toParent, ppid, probfile, thm, sg_num, names_arr)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   216
 end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   217
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   218
end;