src/HOL/Tools/ATP/AtpCommunication.ML
author wenzelm
Fri, 15 Dec 2006 00:08:06 +0100
changeset 21858 05f57309170c
parent 20826 32640c8956e7
child 21888 c75a44597fb7
permissions -rw-r--r--
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
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 checkEProofFound: 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    13
          TextIO.instream * TextIO.outstream * Posix.Process.pid * 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    14
          string * string Array.array -> bool
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    15
    val checkVampProofFound: 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    16
          TextIO.instream * TextIO.outstream * Posix.Process.pid * 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    17
          string * string Array.array -> bool
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    18
    val checkSpassProofFound:  
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    19
          TextIO.instream * TextIO.outstream * Posix.Process.pid * 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
    20
          string * thm * int * string Array.array -> bool
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
    21
    val signal_parent:  
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
    22
          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
    23
  end;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    24
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    25
structure AtpCommunication : ATP_COMMUNICATION =
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    26
struct
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    27
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    28
val trace_path = Path.basic "atp_trace";
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    29
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    30
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
    31
              else ();
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
    32
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    33
exception EOF;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
    34
20762
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    35
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    36
(**** retrieve the axioms that were used in the proof ****)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    37
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    38
(*Get names of axioms used. Axioms are indexed from 1, while the array is indexed from 0*)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    39
fun get_axiom_names (names_arr: string array) step_nums = 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    40
    let fun is_axiom n = n <= Array.length names_arr 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    41
        fun index i = Array.sub(names_arr, i-1)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    42
        val axnums = List.filter is_axiom step_nums
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    43
        val axnames = sort_distinct string_ord (map index axnums)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    44
    in
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    45
	if length axnums = length step_nums then "UNSOUND!!" :: axnames
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    46
	else axnames
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    47
    end
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    48
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    49
 (*String contains multiple lines. We want those of the form 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    50
     "253[0:Inp] et cetera..."
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    51
  A list consisting of the first number in each line is returned. *)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    52
fun get_spass_linenums proofstr = 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    53
  let val toks = String.tokens (not o Char.isAlphaNum)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    54
      fun inputno (ntok::"0"::"Inp"::_) = Int.fromString ntok
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    55
        | inputno _ = NONE
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    56
      val lines = String.tokens (fn c => c = #"\n") proofstr
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    57
  in  List.mapPartial (inputno o toks) lines  end
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    58
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    59
fun get_axiom_names_spass proofstr names_arr =
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    60
   get_axiom_names names_arr (get_spass_linenums proofstr);
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    61
    
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    62
 (*String contains multiple lines. We want those of the form 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    63
   "number : ...: ...: initial..." *)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    64
fun get_e_linenums proofstr = 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    65
  let val fields = String.fields (fn c => c = #":")
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    66
      val nospaces = String.translate (fn c => if c = #" " then "" else str c)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    67
      fun initial s = String.isPrefix "initial" (nospaces s)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    68
      fun firstno (line :: _ :: _ :: rule :: _) = 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    69
            if initial rule then Int.fromString line else NONE
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    70
        | firstno _ = NONE
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    71
      val lines = String.tokens (fn c => c = #"\n") proofstr
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    72
  in  List.mapPartial (firstno o fields) lines  end
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    73
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    74
fun get_axiom_names_e proofstr names_arr =
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    75
   get_axiom_names names_arr (get_e_linenums proofstr);
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    76
    
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    77
 (*String contains multiple lines. We want those of the form 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    78
     "*********** [448, input] ***********".
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    79
  A list consisting of the first number in each line is returned. *)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    80
fun get_vamp_linenums proofstr = 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    81
  let val toks = String.tokens (not o Char.isAlphaNum)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    82
      fun inputno [ntok,"input"] = Int.fromString ntok
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    83
        | inputno _ = NONE
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    84
      val lines = String.tokens (fn c => c = #"\n") proofstr
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    85
  in  List.mapPartial (inputno o toks) lines  end
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    86
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    87
fun get_axiom_names_vamp proofstr names_arr =
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    88
   get_axiom_names names_arr (get_vamp_linenums proofstr);
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    89
    
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    90
fun rules_to_string [] = "NONE"
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    91
  | rules_to_string xs = space_implode "  " xs
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    92
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    93
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    94
(*The signal handler in watcher.ML must be able to read the output of this.*)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    95
fun prover_lemma_list_aux getax proofstr probfile toParent ppid names_arr = 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    96
 let val _ = trace
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    97
               ("\n\nGetting lemma names. proofstr is " ^ proofstr ^
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    98
                "\nprobfile is " ^ probfile ^
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
    99
                "  num of clauses is " ^ string_of_int (Array.length names_arr))
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   100
     val axiom_names = getax proofstr names_arr
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   101
     val ax_str = rules_to_string axiom_names
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   102
    in 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   103
	 trace ("\nDone. Lemma list is " ^ ax_str);
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   104
         TextIO.output (toParent, "Success. Lemmas used in automatic proof: " ^
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   105
                  ax_str ^ "\n");
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   106
	 TextIO.output (toParent, probfile ^ "\n");
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   107
	 TextIO.flushOut toParent;
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   108
	 Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   109
    end
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   110
    handle exn => (*FIXME: exn handler is too general!*)
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   111
     (trace ("\nprover_lemma_list_aux: In exception handler: " ^ 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   112
             Toplevel.exn_message exn);
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   113
      TextIO.output (toParent, "Translation failed for the proof: " ^ 
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   114
                     String.toString proofstr ^ "\n");
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   115
      TextIO.output (toParent, probfile);
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   116
      TextIO.flushOut toParent;
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   117
      Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2));
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   118
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   119
val e_lemma_list = prover_lemma_list_aux get_axiom_names_e;
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   120
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   121
val vamp_lemma_list = prover_lemma_list_aux get_axiom_names_vamp;
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   122
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   123
val spass_lemma_list = prover_lemma_list_aux get_axiom_names_spass;
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   124
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   125
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   126
(**** Extracting proofs from an ATP's output ****)
20762
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   127
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   128
(*Return everything in s that comes before the string t*)
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   129
fun cut_before t s = 
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   130
  let val (s1,s2) = Substring.position t (Substring.full s)
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 20826
diff changeset
   131
      val _ = Substring.size s2 <> 0
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 20826
diff changeset
   132
        orelse error "cut_before: string not found"
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   133
  in Substring.string s2 end;
20762
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   134
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   135
val start_E = "# Proof object starts here."
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   136
val end_E   = "# Proof object ends here."
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   137
val start_V6 = "%================== Proof: ======================"
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   138
val end_V6   = "%==============  End of proof. =================="
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   139
val start_V8 = "=========== Refutation =========="
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   140
val end_V8 = "======= End of refutation ======="
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   141
val end_SPASS = "Formulae used in the proof"
17484
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
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   144
(*  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
   145
(*  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
   146
(*********************************************************************************)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   147
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   148
fun startTransfer (endS, fromChild, toParent, ppid, probfile, names_arr) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   149
 let fun transferInput currentString =
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   150
      let val thisLine = TextIO.inputLine fromChild
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   151
      in
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   152
	if thisLine = "" (*end of file?*)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   153
	then (trace ("\n extraction_failed.  End bracket: " ^ endS ^
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   154
	             "\naccumulated text: " ^ currentString);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   155
	      raise EOF)                    
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   156
	else if String.isPrefix endS thisLine
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   157
	then let val proofextract = currentString ^ cut_before endS thisLine
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   158
	         val lemma_list = if endS = end_V8 then vamp_lemma_list
20762
a7a5157c5e75 clearout of obsolete code
paulson
parents: 19199
diff changeset
   159
			  	  else e_lemma_list
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   160
	     in
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   161
	       trace ("\nExtracted proof:\n" ^ proofextract); 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   162
	       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
   163
	     end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   164
	else transferInput (currentString^thisLine)
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   165
      end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   166
 in
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   167
     transferInput "";  true
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   168
 end handle EOF => false
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   169
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   170
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   171
(*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
   172
fun signal_parent (toParent, ppid, msg, probfile) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   173
 (TextIO.output (toParent, msg);
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   174
  TextIO.output (toParent, probfile ^ "\n");
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   175
  TextIO.flushOut toParent;
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   176
  trace ("\nSignalled parent: " ^ msg ^ probfile);
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   177
  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
   178
  (*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
   179
  OS.Process.sleep (Time.fromMilliseconds 600));
17484
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
(*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
   182
fun checkVampProofFound (fromChild, toParent, ppid, probfile, names_arr) =
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   183
 let val thisLine = TextIO.inputLine fromChild
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   184
 in   
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   185
     trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   186
     if thisLine = "" 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   187
     then (trace "\nNo proof output seen"; false)
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   188
     else if String.isPrefix start_V8 thisLine
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   189
     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
   190
     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
   191
             (String.isPrefix "Refutation not found" thisLine)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   192
     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
   193
	   true)
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   194
     else 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
   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
(*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
   198
fun checkEProofFound (fromChild, toParent, ppid, probfile, names_arr) = 
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   199
 let val thisLine = TextIO.inputLine fromChild  
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   200
 in   
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   201
     trace thisLine;
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   202
     if thisLine = "" then (trace "\nNo proof output seen"; false)
17569
c1143a96f6d7 improved proof parsing
paulson
parents: 17525
diff changeset
   203
     else if String.isPrefix start_E thisLine
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   204
     then 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
   205
     else if String.isPrefix "# Problem is satisfiable" thisLine
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   206
     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
   207
	   true)
8ba7c3cd24a8 time limit option; fixed bug concerning first line of ATP output
paulson
parents: 17583
diff changeset
   208
     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
   209
     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
   210
	   true)
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   211
     else 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
   212
 end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   213
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   214
(*FIXME: can't these two functions be replaced by startTransfer above?*)
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   215
fun transferSpassInput (fromChild, toParent, ppid, probfile,
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   216
                        currentString, thm, sg_num, names_arr) = 
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   217
 let val thisLine = TextIO.inputLine fromChild 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   218
 in 
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   219
    trace thisLine;
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   220
    if thisLine = "" (*end of file?*)
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   221
    then (trace ("\nspass_extraction_failed: " ^ currentString);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   222
	  raise EOF)                    
18700
f04a8755d6ca improved SPASS support
paulson
parents: 17773
diff changeset
   223
    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
   224
    then 
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   225
      let val proofextract = currentString ^ cut_before end_SPASS thisLine
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   226
      in 
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   227
	 trace ("\nextracted spass proof: " ^ proofextract);
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   228
	 spass_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
   229
      end
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   230
    else transferSpassInput (fromChild, toParent, ppid, probfile,
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   231
			     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
   232
 end;
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   233
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   234
(*Inspect the output of a SPASS process to see if it has found a proof,   
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   235
  and if so, transfer output to the input pipe of the main Isabelle process*)
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   236
fun 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
   237
   let val thisLine = TextIO.inputLine fromChild  
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   238
   in                 
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   239
      if thisLine = "" then false
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   240
      else if String.isPrefix "Here is a proof" thisLine then     
18700
f04a8755d6ca improved SPASS support
paulson
parents: 17773
diff changeset
   241
	 (trace ("\nabout to transfer SPASS proof:\n");
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   242
	  transferSpassInput (fromChild, toParent, ppid, probfile, thisLine, 
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   243
 	                     thm, sg_num,names_arr);
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   244
	  true) handle EOF => false
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   245
      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
   246
    end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   247
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   248
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   249
(*Called from watcher. Returns true if the SPASS process has returned a verdict.*)
20826
32640c8956e7 tidying and simplifying
paulson
parents: 20762
diff changeset
   250
fun checkSpassProofFound (fromChild, toParent, ppid, probfile, thm, sg_num, names_arr) = 
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   251
 let val thisLine = TextIO.inputLine fromChild  
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   252
 in    
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   253
     trace thisLine;
17773
a7258e1020b7 more tidying. Fixed process management bugs and race condition
paulson
parents: 17772
diff changeset
   254
     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
   255
     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
   256
     then      
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   257
        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
   258
     else if thisLine = "SPASS beiseite: Completion found.\n"
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   259
     then (signal_parent (toParent, ppid, "Invalid\n", probfile);
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   260
	   true)
17484
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   261
     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
   262
             thisLine = "SPASS beiseite: Maximal number of loops exceeded.\n"
17772
818cec5f82a4 major simplification: removal of the goalstring argument
paulson
parents: 17746
diff changeset
   263
     then (signal_parent (toParent, ppid, "Failure\n", probfile);
17718
9dab1e491d10 reduction in tracing files
paulson
parents: 17690
diff changeset
   264
	   true)
19199
b338c218cc6e Proof reconstruction now only takes names of theorems as input.
mengj
parents: 18700
diff changeset
   265
    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
   266
 end
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   267
f6a225f97f0a simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
diff changeset
   268
end;