src/HOL/Tools/ATP/ECommunication.ML
changeset 17305 6cef3aedd661
parent 17236 6edb84c661dd
child 17306 5cde710a8a23
equal deleted inserted replaced
17304:c33c9e9df4f8 17305:6cef3aedd661
     7 (***************************************************************************)
     7 (***************************************************************************)
     8 (*  Code to deal with the transfer of proofs from a E process          *)
     8 (*  Code to deal with the transfer of proofs from a E process          *)
     9 (***************************************************************************)
     9 (***************************************************************************)
    10 signature E_COMM =
    10 signature E_COMM =
    11   sig
    11   sig
    12     val reconstruct : bool ref
       
    13     val E: bool ref
    12     val E: bool ref
    14     val getEInput : TextIO.instream -> string * string * string
    13     val getEInput : TextIO.instream -> string * string * string
    15     val checkEProofFound:  TextIO.instream * TextIO.outstream * Posix.Process.pid * string * 
    14     val checkEProofFound: 
    16                                string *string * Thm.thm * int *(ResClause.clause * Thm.thm) Array.array  * int -> bool
    15           TextIO.instream * TextIO.outstream * Posix.Process.pid * string * 
    17     
    16           string * string * thm * int * (ResClause.clause * thm) Array.array * int -> bool
    18   end;
    17   end;
    19 
    18 
    20 structure EComm :E_COMM =
    19 structure EComm : E_COMM =
    21 struct
    20 struct
    22 
    21 
    23 (* switch for whether to reconstruct a proof found, or just list the lemmas used *)
       
    24 val reconstruct = ref true;
       
    25 val E = ref false;
    22 val E = ref false;
    26 
    23 
    27 (***********************************)
    24 (***********************************)
    28 (*  Write E   output to a file *)
    25 (*  Write E   output to a file *)
    29 (***********************************)
    26 (***********************************)
    39 (*  Reconstruct the E proof w.r.t. thmstring (string version of   *)
    36 (*  Reconstruct the E proof w.r.t. thmstring (string version of   *)
    40 (*  Isabelle goal to be proved), then transfer the reconstruction     *)
    37 (*  Isabelle goal to be proved), then transfer the reconstruction     *)
    41 (*  steps as a string to the input pipe of the main Isabelle process  *)
    38 (*  steps as a string to the input pipe of the main Isabelle process  *)
    42 (**********************************************************************)
    39 (**********************************************************************)
    43 
    40 
    44 val atomize_tac = SUBGOAL
       
    45   (fn (prop,_) =>
       
    46       let val ts = Logic.strip_assums_hyp prop
       
    47       in EVERY1 
       
    48 	  [METAHYPS
       
    49 	       (fn hyps => (cut_facts_tac (map (ObjectLogic.atomize_thm o forall_intr_vars) hyps) 1)),
       
    50            REPEAT_DETERM_N (length ts) o (etac thin_rl)]
       
    51   end);
       
    52 
       
    53 
       
    54 fun reconstruct_tac proofextract thmstring goalstring toParent ppid sg_num 
    41 fun reconstruct_tac proofextract thmstring goalstring toParent ppid sg_num 
    55                     clause_arr  (num_of_clauses:int ) = 
    42                     clause_arr num_of_clauses = 
    56  (*FIXME: foo is never used!*)
       
    57  let val foo = TextIO.openOut( File.platform_path(File.tmp_path (Path.basic"foobar3")));
       
    58  in
       
    59    SELECT_GOAL
    43    SELECT_GOAL
    60     (EVERY1 [rtac ccontr,atomize_tac, skolemize_tac, 
    44     (EVERY1 [rtac ccontr, ResLib.atomize_tac, skolemize_tac, 
    61              METAHYPS(fn negs => 
    45              METAHYPS(fn negs => 
    62     ( Recon_Transfer.EString_to_lemmaString proofextract thmstring goalstring 
    46     (Recon_Transfer.EString_to_lemmaString proofextract thmstring goalstring 
    63               toParent ppid negs clause_arr  num_of_clauses ))]) sg_num	
    47               toParent ppid negs clause_arr  num_of_clauses ))]) sg_num	
    64  end ;
       
    65 
    48 
    66 
    49 
    67 fun transferEInput (fromChild, toParent, ppid,thmstring,goalstring, currentString, thm, sg_num,clause_arr,  num_of_clauses) = 
    50 fun transferEInput (fromChild, toParent, ppid,thmstring,goalstring, currentString, thm, sg_num,clause_arr,  num_of_clauses) = 
    68   let val thisLine = TextIO.inputLine fromChild 
    51   let val thisLine = TextIO.inputLine fromChild 
    69   in 
    52   in 
    70      if thisLine = "# Proof object ends here.\n"
    53      if thisLine = "# Proof object ends here.\n"
    71      then 
    54      then 
    72        let val proofextract = Recon_Parse.extract_proof (currentString^thisLine)
    55        let val proofextract = Recon_Parse.extract_proof (currentString^thisLine)
    73        in 
    56        in 
    74 	   File.write (File.tmp_path (Path.basic"foobar2")) proofextract;
    57 	   File.write (File.tmp_path (Path.basic"extracted-prf-E")) proofextract;
    75 	   reconstruct_tac proofextract thmstring goalstring toParent ppid sg_num 
    58 	   reconstruct_tac proofextract thmstring goalstring toParent ppid sg_num 
    76 	       clause_arr num_of_clauses thm
    59 	       clause_arr num_of_clauses thm
    77        end
    60        end
    78      else transferEInput (fromChild, toParent, ppid,thmstring, goalstring,
    61      else transferEInput (fromChild, toParent, ppid,thmstring, goalstring,
    79                               (currentString^thisLine), thm, sg_num, clause_arr,  
    62                               (currentString^thisLine), thm, sg_num, clause_arr,  
    80                               num_of_clauses)
    63                               num_of_clauses)
    81   end;
    64   end;
    82 
    65 
    83 
    66 
    84 (*********************************************************************************)
    67 (*********************************************************************************)
    85 (*  Inspect the output of a E   process to see if it has found a proof,      *)
    68 (*  Inspect the output of an E process to see if it has found a proof,      *)
    86 (*  and if so, transfer output to the input pipe of the main Isabelle process    *)
    69 (*  and if so, transfer output to the input pipe of the main Isabelle process    *)
    87 (*********************************************************************************)
    70 (*********************************************************************************)
    88 
    71 
    89  
    72  
    90 fun startETransfer (fromChild, toParent, ppid, thmstring,goalstring,childCmd,thm, sg_num,clause_arr, num_of_clauses) = 
    73 fun startETransfer (fromChild, toParent, ppid, thmstring,goalstring,childCmd,
    91 (*let val _ = Posix.Process.wait ()
    74                     thm, sg_num,clause_arr, num_of_clauses) = 
    92 in*)
    75   if isSome (TextIO.canInput(fromChild, 5))
    93                                        
    76   then
    94    if (isSome (TextIO.canInput(fromChild, 5)))
    77     let val thisLine = TextIO.inputLine fromChild  
    95    then
    78     in                 
    96    let val thisLine = TextIO.inputLine fromChild  
    79       if String.isPrefix "# Proof object starts" thisLine 
    97    in                 
    80       then     
    98      if String.isPrefix "# Proof object starts" thisLine then     
    81 	 (File.append (File.tmp_path (Path.basic "transfer-E"))
    99        let val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_transfer")))
    82 		      ("about to transfer proof, thm is: " ^ string_of_thm thm);
   100 	   val _=  TextIO.output (outfile, "about to transfer proof, thm is: "^(string_of_thm thm))
    83 	  transferEInput (fromChild, toParent, ppid,thmstring, goalstring,thisLine, 
   101 	   val _ =  TextIO.closeOut outfile
    84 			      thm, sg_num,clause_arr,  num_of_clauses);
   102        in
    85 	  true)
   103  	 transferEInput (fromChild, toParent, ppid,thmstring, goalstring,thisLine, 
    86       else startETransfer (fromChild, toParent, ppid, thmstring, goalstring,
   104  	                     thm, sg_num,clause_arr,  num_of_clauses);
    87 			       childCmd, thm, sg_num,clause_arr, num_of_clauses)
   105  	 true
    88      end
   106        end     
    89    else false
   107      else startETransfer (fromChild, toParent, ppid, thmstring, goalstring,
    90 
   108                               childCmd, thm, sg_num,clause_arr, num_of_clauses)
    91 
   109     end
    92 fun checkEProofFound (fromChild, toParent, ppid,thmstring,goalstring, childCmd, thm, sg_num, clause_arr,  num_of_clauses) = 
   110      else false
       
   111  (*  end*)
       
   112 
       
   113 
       
   114 fun checkEProofFound (fromChild, toParent, ppid,thmstring,goalstring, childCmd, thm, sg_num, clause_arr,  (num_of_clauses:int )) = 
       
   115   let val E_proof_file = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "E_proof")))
    93   let val E_proof_file = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "E_proof")))
   116       val _ = File.write(File.tmp_path (Path.basic "foo_checkE"))
    94         val _ = File.write (File.tmp_path (Path.basic "checking-prf-E"))
   117                  ("checking if proof found, thm is: "^(string_of_thm thm))
    95                            ("checking if proof found, thm is: " ^ string_of_thm thm)
   118   in 
    96   in 
   119   if (isSome (TextIO.canInput(fromChild, 5)))
    97   if (isSome (TextIO.canInput(fromChild, 5)))
   120   then
    98   then
   121   let val thisLine = TextIO.inputLine fromChild  
    99   let val thisLine = TextIO.inputLine fromChild  
   122       in if (*thisLine = "# Problem is unsatisfiable (or provable), constructing proof object\n"*)
   100       in if (*thisLine = "# Problem is unsatisfiable (or provable), constructing proof object\n"*)
   123              thisLine = "# # TSTP exit status: Unsatisfiable\n"
   101              thisLine = "# TSTP exit status: Unsatisfiable\n"
   124 	 then      
   102 	 then      
   125 	    let val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_proof")));                                                                                (*val _ =  Posix.Process.sleep(Time.fromSeconds 3 );*)
   103 	    let val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_proof")));                                                                                (*val _ =  Posix.Process.sleep(Time.fromSeconds 3 );*)
   126 		val _ = TextIO.output (outfile, thisLine)
   104 		val _ = TextIO.output (outfile, thisLine)
   127 	
   105 	
   128 		val _ = TextIO.closeOut outfile
   106 		val _ = TextIO.closeOut outfile
   129 	    in 
   107 	    in 
   130 	       startETransfer (fromChild, toParent, ppid, thmstring,goalstring,childCmd, thm, sg_num, clause_arr,  num_of_clauses) 
   108 	       startETransfer (fromChild, toParent, ppid, thmstring,goalstring,childCmd, thm, sg_num, clause_arr,  num_of_clauses) 
   131 	    end
   109 	    end
   132 	 else if thisLine= "# Problem is satisfiable (or invalid), generating saturation derivation\n"
   110 	 else if thisLine= "# Problem is satisfiable (or invalid), generating saturation derivation\n"
   133 	 then  
   111 	 then  
   134 	    let val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_proof")));                                                                               (* val _ =  Posix.Process.sleep(Time.fromSeconds 3 );*)
   112 	    let val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_proof"))); 
   135 		val _ = TextIO.output (outfile, thisLine)
   113 		val _ = TextIO.output (outfile, thisLine)
   136 
       
   137 		val _ =  TextIO.closeOut outfile
   114 		val _ =  TextIO.closeOut outfile
   138 	    in
   115 	    in
   139 	      TextIO.output (toParent,childCmd^"\n" );
   116 	      TextIO.output (toParent,childCmd^"\n" );
   140 	      TextIO.flushOut toParent;
   117 	      TextIO.flushOut toParent;
   141 	      TextIO.output (E_proof_file, thisLine);
   118 	      TextIO.output (E_proof_file, thisLine);