src/HOL/Tools/ATP/recon_transfer_proof.ML
changeset 16905 fa26952fa7b6
parent 16803 014090d1e64b
child 17122 278eb6251dc0
equal deleted inserted replaced
16904:6fb188ca5f91 16905:fa26952fa7b6
    12 
    12 
    13 open Recon_Parse
    13 open Recon_Parse
    14 
    14 
    15 infixr 8 ++; infixr 7 >>; infixr 6 ||;
    15 infixr 8 ++; infixr 7 >>; infixr 6 ||;
    16 
    16 
    17 
       
    18 
       
    19 (*
       
    20 fun fill_cls_array array n [] = ()
       
    21 |   fill_cls_array array n (x::xs) = let val _ = Array.update (array, n,x)
       
    22                                      in
       
    23                                         fill_cls_array array (n+1) (xs)
       
    24                                      end;
       
    25 
       
    26 
       
    27 
       
    28 fun memo_add_clauses ((name:string, (cls:Thm.thm list)), symtable)=
       
    29                         symtable := Symtab.update((name , cls), !symtable);
       
    30       	       
       
    31 
       
    32 fun memo_add_all ([], symtable) = ()
       
    33 |   memo_add_all ((x::xs),symtable) = let val _ = memo_add_clauses (x, symtable)
       
    34                            in
       
    35                                memo_add_all (xs, symtable)
       
    36                            end
       
    37 
       
    38 fun memo_find_clause (name, (symtable: Thm.thm list Symtab.table ref)) = case Symtab.lookup (!symtable,name) of
       
    39       	        NONE =>  []
       
    40                 |SOME cls  => cls ;
       
    41       	        	
       
    42 
       
    43 fun retrieve_clause array symtable clausenum = let
       
    44                                                   val (name, clnum) = Array.sub(array, clausenum)
       
    45                                                   val clauses = memo_find_clause (name, symtable)
       
    46                                                   val clause = get_nth clnum clauses
       
    47                                                in
       
    48                                                   (name, clause)
       
    49                                                end
       
    50  *)                                             
       
    51 
    17 
    52 (* Versions that include type information *)
    18 (* Versions that include type information *)
    53  
    19  
    54 (* FIXME rename to str_of_thm *)
    20 (* FIXME rename to str_of_thm *)
    55 fun string_of_thm thm =
    21 fun string_of_thm thm =
   249    in
   215    in
   250       clasimp_names
   216       clasimp_names
   251    end
   217    end
   252     
   218     
   253 
   219 
   254 
       
   255 
       
   256 (***********************************************)
   220 (***********************************************)
   257 (* get axioms for reconstruction               *)
   221 (* get axioms for reconstruction               *)
   258 (***********************************************)
   222 (***********************************************)
   259 fun numclstr (vars, []) str = str
   223 fun numclstr (vars, []) str = str
   260 |   numclstr ( vars, ((num, thm)::rest)) str =
   224 |   numclstr ( vars, ((num, thm)::rest)) str =
   265 
   229 
   266 fun addvars c (a,b)  = (a,b,c)
   230 fun addvars c (a,b)  = (a,b,c)
   267 
   231 
   268  fun get_axioms_used proof_steps thms clause_arr num_of_clauses  =
   232  fun get_axioms_used proof_steps thms clause_arr num_of_clauses  =
   269      let 
   233      let 
   270 	 (*val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_ax_thmstr")))                                                                      
       
   271 	 val _ = TextIO.output (outfile, thmstring)
       
   272 	 
       
   273 	 val _ =  TextIO.closeOut outfile*)
       
   274 	(* not sure why this is necessary again, but seems to be *)
       
   275 
       
   276 	val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   234 	val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   277 	val axioms = get_init_axioms proof_steps
   235 	val axioms = get_init_axioms proof_steps
   278 	val step_nums = get_step_nums axioms []
   236 	val step_nums = get_step_nums axioms []
   279 
   237 
   280        (***********************************************)
   238        (***********************************************)
   282        (***********************************************)
   240        (***********************************************)
   283 
   241 
   284        (* val clasimp_names_cls = get_clasimp_cls clause_arr   num_of_clauses step_nums   
   242        (* val clasimp_names_cls = get_clasimp_cls clause_arr   num_of_clauses step_nums   
   285 	val clasimp_names = map #1 clasimp_names_cls
   243 	val clasimp_names = map #1 clasimp_names_cls
   286 	val clasimp_cls = map #2 clasimp_names_cls
   244 	val clasimp_cls = map #2 clasimp_names_cls
   287 	val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "clasimp_names")))                                                            val clasimp_namestr = concat clasimp_names                            
   245 	val _ = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "clasimp_names")))                                                            val clasimp_namestr = concat clasimp_names                            
   288 	 val _ = TextIO.output (outfile,clasimp_namestr)
   246 	 val _ = TextIO.output (outfile,clasimp_namestr)
   289 	 
   247 	 
   290 	 val _ =  TextIO.closeOut outfile
   248 	 val _ =  TextIO.closeOut outfile
   291 *)
   249 *)
   292 
   250 
   307 
   265 
   308 	(* literals of -all- axioms, not just those used by spass *)
   266 	(* literals of -all- axioms, not just those used by spass *)
   309 	val meta_strs = map ReconOrderClauses.get_meta_lits metas
   267 	val meta_strs = map ReconOrderClauses.get_meta_lits metas
   310        
   268        
   311 	val metas_and_strs = ListPair.zip (metas,meta_strs)
   269 	val metas_and_strs = ListPair.zip (metas,meta_strs)
   312 	 val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_clauses")));                                                                       
   270 	val _ = File.write(File.tmp_path (Path.basic "foo_clauses")) (onestr ax_strs)
   313 	 val _ = TextIO.output (outfile, onestr ax_strs)
   271 	val _ = File.write(File.tmp_path (Path.basic "foo_metastrs")) (onestr meta_strs)
   314 	 
       
   315 	 val _ =  TextIO.closeOut outfile
       
   316 	 val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_metastrs")));                                                                       
       
   317 	 val _ = TextIO.output (outfile, onestr meta_strs)
       
   318 	 val _ =  TextIO.closeOut outfile
       
   319 
   272 
   320 	(* get list of axioms as thms with their variables *)
   273 	(* get list of axioms as thms with their variables *)
   321 
   274 
   322 	val ax_metas = get_assoc_snds ax_strs metas_and_strs []
   275 	val ax_metas = get_assoc_snds ax_strs metas_and_strs []
   323 	val ax_vars = map thm_vars ax_metas
   276 	val ax_vars = map thm_vars ax_metas
   325 
   278 
   326 	(* get list of extra axioms as thms with their variables *)
   279 	(* get list of extra axioms as thms with their variables *)
   327 	val extra_metas = add_if_not_inlist metas ax_metas []
   280 	val extra_metas = add_if_not_inlist metas ax_metas []
   328 	val extra_vars = map thm_vars extra_metas
   281 	val extra_vars = map thm_vars extra_metas
   329 	val extra_with_vars = if (not (extra_metas = []) ) 
   282 	val extra_with_vars = if (not (extra_metas = []) ) 
   330 			      then
   283 			      then ListPair.zip (extra_metas,extra_vars)
   331 				     ListPair.zip (extra_metas,extra_vars)
   284 			      else []
   332 			      else
       
   333 				     []
       
   334 
       
   335        (* val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   285        (* val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   336        val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_metas")))
   286        val _ = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_metas")))
   337 
   287 
   338        val _ = TextIO.output (outfile, ((thmstrings ax_metas "")))
   288        val _ = TextIO.output (outfile, ((thmstrings ax_metas "")))
   339        val _ =  TextIO.closeOut outfile
   289        val _ =  TextIO.closeOut outfile
   340       val foo_metas =  File.platform_path(File.tmp_path (Path.basic "foo_metas"))
   290       val foo_metas =  File.platform_path(File.tmp_path (Path.basic "foo_metas"))
   341       val foo_metas2 =   File.platform_path(File.tmp_path (Path.basic "foo_metas2"))
   291       val foo_metas2 =   File.platform_path(File.tmp_path (Path.basic "foo_metas2"))
   342 	val execperl = Unix.execute("/usr/bin/perl", ["remchars.pl", "  <", foo_metas, "  >", foo_metas2])
   292 	val execperl = Unix.execute("/usr/bin/perl", ["remchars.pl", "  <", foo_metas, "  >", foo_metas2])
   343      val infile = TextIO.openIn(File.platform_path(File.tmp_path (Path.basic "foo_metas2")))
   293      val infile = TextIO.openIn(File.platform_path(File.tmp_path (Path.basic "foo_metas2")))
   344     val ax_metas_str = TextIO.inputLine (infile)
   294     val ax_metas_str = TextIO.inputLine (infile)
   345     val _ = TextIO.closeIn infile
   295     val _ = TextIO.closeIn infile
   346        val _= (print_mode := (["xsymbols", "symbols"] @ ! print_mode))*)
   296        val _= (print_mode := (["xsymbols", "symbols"] @ ! print_mode))*)
   347        
       
   348      in
   297      in
   349 	(distfrees,distvars, extra_with_vars,ax_with_vars, (*clasimp_names*)(ListPair.zip (step_nums,ax_metas)))
   298 	(distfrees,distvars, extra_with_vars,ax_with_vars, (*clasimp_names*)(ListPair.zip (step_nums,ax_metas)))
   350      end
   299      end;
   351     
   300                                             
   352 
       
   353                                         
       
   354 
   301 
   355 (*********************************************************************)
   302 (*********************************************************************)
   356 (* Pass in spass string of proof and string version of isabelle goal *)
   303 (* Pass in spass string of proof and string version of isabelle goal *)
   357 (* Get out reconstruction steps as a string to be sent to Isabelle   *)
   304 (* Get out reconstruction steps as a string to be sent to Isabelle   *)
   358 (*********************************************************************)
   305 (*********************************************************************)
   370 \1279[0:Inp] ||  -> equal(const_Nat_Osize(tconst_fun(tconst_List_Olist(U),tconst_nat),const_List_Olist_ONil),const_0)**.\
   317 \1279[0:Inp] ||  -> equal(const_Nat_Osize(tconst_fun(tconst_List_Olist(U),tconst_nat),const_List_Olist_ONil),const_0)**.\
   371 \1430[0:Inp] || equal(const_Nat_Osize(tconst_fun(tconst_List_Olist(typ__Ha),tconst_nat),const_List_Orev(tconst_fun(tconst_List_Olist(typ__Ha),tconst_List_Olist(typ__Ha)),const_List_Olist_ONil)),const_Nat_Osize(tconst_fun(tconst_List_Olist(typ__Ha),tconst_nat),const_List_Olist_ONil))** -> .\
   318 \1430[0:Inp] || equal(const_Nat_Osize(tconst_fun(tconst_List_Olist(typ__Ha),tconst_nat),const_List_Orev(tconst_fun(tconst_List_Olist(typ__Ha),tconst_List_Olist(typ__Ha)),const_List_Olist_ONil)),const_Nat_Osize(tconst_fun(tconst_List_Olist(typ__Ha),tconst_nat),const_List_Olist_ONil))** -> .\
   372 \1453[0:Rew:1279.0,1430.0,1242.0,1430.0,1279.0,1430.0] || equal(const_0,const_0)* -> .\
   319 \1453[0:Rew:1279.0,1430.0,1242.0,1430.0,1279.0,1430.0] || equal(const_0,const_0)* -> .\
   373 \1454[0:Obv:1453.0] ||  -> .";*)
   320 \1454[0:Obv:1453.0] ||  -> .";*)
   374 
   321 
   375 fun subst_for a b [] = ""
   322 fun subst_for a b = String.translate (fn c => str (if c=a then b else c));
   376   | subst_for a b (x :: xs) =
   323 
   377       if x = a
   324 val remove_linebreaks = subst_for #"\n" #"\t";
   378       then 
   325 val restore_linebreaks = subst_for #"\t" #"\n";
   379 	b ^ subst_for a b xs
       
   380       else
       
   381 	x ^ subst_for a b xs;
       
   382 
       
   383 val remove_linebreaks = subst_for "\n" "\t" o explode;
       
   384 val restore_linebreaks = subst_for "\t" "\n" o explode;
       
   385 
       
   386 
   326 
   387 fun spassString_to_lemmaString proofstr thmstring goalstring toParent ppid thms clause_arr  num_of_clauses  = 
   327 fun spassString_to_lemmaString proofstr thmstring goalstring toParent ppid thms clause_arr  num_of_clauses  = 
   388            let 	val  outfile = TextIO.openAppend( File.platform_path(File.tmp_path (Path.basic"thmstringfile")));          
   328   let val _ = File.append(File.tmp_path (Path.basic"thmstringfile"))
   389 		val _ = TextIO.output (outfile, ("thmstring is: "^thmstring^"\n proofstr is: "^proofstr^"\n goalstr is: "^goalstring^" \n  num of clauses is: "^(string_of_int num_of_clauses)))
   329                   ("thmstring is: "^thmstring^"\n proofstr is: "^proofstr^"\n goalstr is: "^goalstring^" \n  num of clauses is: "^(string_of_int num_of_clauses))
   390 
   330 
   391               	val _ =  TextIO.closeOut outfile
   331      (***********************************)
   392 
   332      (* parse spass proof into datatype *)
   393                  (***********************************)
   333      (***********************************)
   394                  (* parse spass proof into datatype *)
   334       val tokens = #1(lex proofstr)
   395                  (***********************************)
   335       val proof_steps1 = parse tokens
   396          
   336       val proof_steps = just_change_space proof_steps1
   397                   val tokens = #1(lex proofstr)
   337       val _ = File.write (File.tmp_path (Path.basic "foo_parse")) ("Did parsing on "^proofstr)
   398                   val proof_steps1 = parse tokens
   338       val _ = File.write(File.tmp_path (Path.basic "foo_thmstring_at_parse"))
   399                   val proof_steps = just_change_space proof_steps1
   339                         ("Parsing for thmstring: "^thmstring)
   400                   val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_parse")));        val _ = TextIO.output (outfile, ("Did parsing on "^proofstr))
   340       (************************************)
   401                                                   val _ =  TextIO.closeOut outfile
   341       (* recreate original subgoal as thm *)
   402                                                 
   342       (************************************)
   403                                                   val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_thmstring_at_parse")));                                        val _ = TextIO.output (outfile, ("Parsing for thmstring: "^thmstring))
   343     
   404                                                   val _ =  TextIO.closeOut outfile
   344       (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
   405                                               (************************************)
   345       (* need to get prems_of thm, then get right one of the prems, relating to whichever*)
   406                                               (* recreate original subgoal as thm *)
   346       (* subgoal this is, and turn it into meta_clauses *)
   407                                               (************************************)
   347       (* should prob add array and table here, so that we can get axioms*)
   408                                                 
   348       (* produced from the clasimpset rather than the problem *)
   409                                                   (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
   349 
   410                                                   (* need to get prems_of thm, then get right one of the prems, relating to whichever*)
   350       val (axiom_names) = get_axiom_names proof_steps  thms clause_arr  num_of_clauses
   411                                                   (* subgoal this is, and turn it into meta_clauses *)
   351       val ax_str = "Rules from clasimpset used in proof found by SPASS: "^(rules_to_string axiom_names "")
   412                                                   (* should prob add array and table here, so that we can get axioms*)
   352       val _ = File.append(File.tmp_path (Path.basic "reconstrfile"))
   413                                                   (* produced from the clasimpset rather than the problem *)
   353                          ("reconstring is: "^ax_str^"  "^goalstring)       
   414 
   354   in 
   415                                                   val (axiom_names) = get_axiom_names proof_steps  thms clause_arr  num_of_clauses
   355        TextIO.output (toParent, ax_str^"\n");
   416                                                   val ax_str = "Rules from clasimpset used in proof found by SPASS: "^(rules_to_string axiom_names "")
   356        TextIO.flushOut toParent;
   417                                                   val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "reconstrfile")));                                                     val _ = TextIO.output (outfile, ("reconstring is: "^ax_str^"  "^goalstring))
   357        TextIO.output (toParent, "goalstring: "^goalstring^"\n");
   418                                                   val _ =  TextIO.closeOut outfile
   358        TextIO.flushOut toParent;
   419                                                    
   359        TextIO.output (toParent, "thmstring: "^thmstring^"\n");
   420                                               in 
   360        TextIO.flushOut toParent;
   421                                                    TextIO.output (toParent, ax_str^"\n");
   361 
   422                                                    TextIO.flushOut toParent;
   362        Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   423                                         	   TextIO.output (toParent, "goalstring: "^goalstring^"\n");
   363       (* Attempt to prevent several signals from turning up simultaneously *)
   424                                          	   TextIO.flushOut toParent;
   364        Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
   425                                          	   TextIO.output (toParent, "thmstring: "^thmstring^"\n");
   365   end
   426                                          	   TextIO.flushOut toParent;
   366   handle _ => 
   427                                           
   367   let val _ = File.write(File.tmp_path (Path.basic "foo_handler")) "In exception handler"
   428                                          	   Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   368   in 
   429                                          	  (* Attempt to prevent several signals from turning up simultaneously *)
   369      TextIO.output (toParent,"Proof found but parsing failed for resolution proof: "^(remove_linebreaks proofstr)^"\n" );
   430                                          	   Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
   370       TextIO.flushOut toParent;
   431                                               end
   371        TextIO.output (toParent, (remove_linebreaks thmstring)^"\n");
   432                                               handle _ => (let val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_handler")));
   372        TextIO.flushOut toParent;
   433 
   373        TextIO.output (toParent, ( (remove_linebreaks goalstring)^"\n"));
   434                                                   val _ = TextIO.output (outfile, ("In exception handler"));
   374        TextIO.flushOut toParent;
   435                                                   val _ =  TextIO.closeOut outfile
   375       Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   436                                               in 
   376       (* Attempt to prevent several signals from turning up simultaneously *)
   437                                                  TextIO.output (toParent,"Proof found but parsing failed for resolution proof: "^(remove_linebreaks proofstr)^"\n" );
   377       Posix.Process.sleep(Time.fromSeconds 1) ;dummy_tac
   438                                                   TextIO.flushOut toParent;
   378   end
   439 						   TextIO.output (toParent, (remove_linebreaks thmstring)^"\n");
       
   440                                          	   TextIO.flushOut toParent;
       
   441                                          	   TextIO.output (toParent, ( (remove_linebreaks goalstring)^"\n"));
       
   442                                          	   TextIO.flushOut toParent;
       
   443             					  Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
       
   444                                          	  (* Attempt to prevent several signals from turning up simultaneously *)
       
   445                                          	  Posix.Process.sleep(Time.fromSeconds 1) ;dummy_tac
       
   446                                               end)
       
   447 
   379 
   448 
   380 
   449 fun vampString_to_lemmaString proofstr thmstring goalstring toParent ppid thms clause_arr  num_of_clauses  = 
   381 fun vampString_to_lemmaString proofstr thmstring goalstring toParent ppid thms clause_arr  num_of_clauses  = 
   450            let val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "thmstringfile")));     						       val _ = TextIO.output (outfile, (" thmstring is: "^thmstring^"proofstr is: "^proofstr^"goalstr is: "^goalstring^" num of clauses is: "^(string_of_int num_of_clauses)))
   382  let val _ = File.append(File.tmp_path (Path.basic "thmstringfile"))
   451                                                val _ =  TextIO.closeOut outfile
   383                (" thmstring is: "^thmstring^"proofstr is: "^proofstr^
   452 
   384                 "goalstr is: "^goalstring^" num of clauses is: "^
   453                                               (***********************************)
   385                 (string_of_int num_of_clauses))
   454                                               (* get vampire axiom names         *)
   386 
   455                                               (***********************************)
   387     (***********************************)
   456          
   388     (* get vampire axiom names         *)
   457                                                val (axiom_names) = get_axiom_names_vamp proofstr  thms clause_arr  num_of_clauses
   389     (***********************************)
   458                                                val ax_str = "Rules from clasimpset used in proof found by Vampire: "^(rules_to_string axiom_names "")
   390 
   459                                                val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "reconstrfile")));                                                    val _ = TextIO.output (outfile, ("reconstring is: "^ax_str^"  "^goalstring))
   391      val (axiom_names) = get_axiom_names_vamp proofstr  thms clause_arr  num_of_clauses
   460                                                val _ =  TextIO.closeOut outfile
   392      val ax_str = "Rules from clasimpset used in proof found by Vampire: "^(rules_to_string axiom_names "")
   461                                                    
   393     in 
   462                                               in 
   394 	 File.append(File.tmp_path (Path.basic "reconstrfile")) ("reconstring is: "^ax_str^"  "^goalstring);
   463                                                    TextIO.output (toParent, ax_str^"\n");
   395          TextIO.output (toParent, ax_str^"\n");
   464                                                    TextIO.flushOut toParent;
   396 	 TextIO.flushOut toParent;
   465                                         	   TextIO.output (toParent, "goalstring: "^goalstring^"\n");
   397 	 TextIO.output (toParent, "goalstring: "^goalstring^"\n");
   466                                          	   TextIO.flushOut toParent;
   398 	 TextIO.flushOut toParent;
   467                                          	   TextIO.output (toParent, "thmstring: "^thmstring^"\n");
   399 	 TextIO.output (toParent, "thmstring: "^thmstring^"\n");
   468                                          	   TextIO.flushOut toParent;
   400 	 TextIO.flushOut toParent;
   469                                           
   401 
   470                                          	   Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   402 	 Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   471                                          	  (* Attempt to prevent several signals from turning up simultaneously *)
   403 	(* Attempt to prevent several signals from turning up simultaneously *)
   472                                          	   Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
   404 	 Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
   473                                               end
   405     end
   474                                               handle _ => (let val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_handler")));
   406     handle _ => 
   475 
   407     let val _ = File.write(File.tmp_path (Path.basic "foo_handler")) "In exception handler"
   476                                                   val _ = TextIO.output (outfile, ("In exception handler"));
   408     in 
   477                                                   val _ =  TextIO.closeOut outfile
   409 	TextIO.output (toParent,"Proof found by Vampire but translation failed for resolution proof: "^(remove_linebreaks proofstr) );
   478                                               in 
   410 	TextIO.flushOut toParent;
   479                                                   TextIO.output (toParent,"Proof found by Vampire but translation failed for resolution proof: "^(remove_linebreaks proofstr) );
   411 	 TextIO.output (toParent, thmstring^"\n");
   480                                                   TextIO.flushOut toParent;
   412 	 TextIO.flushOut toParent;
   481 						   TextIO.output (toParent, thmstring^"\n");
   413 	 TextIO.output (toParent, goalstring^"\n");
   482                                          	   TextIO.flushOut toParent;
   414 	 TextIO.flushOut toParent;
   483                                          	   TextIO.output (toParent, goalstring^"\n");
   415 	Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   484                                          	   TextIO.flushOut toParent;
   416 	(* Attempt to prevent several signals from turning up simultaneously *)
   485             					  Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   417 	Posix.Process.sleep(Time.fromSeconds 1) ;dummy_tac
   486                                          	  (* Attempt to prevent several signals from turning up simultaneously *)
   418     end;
   487                                          	  Posix.Process.sleep(Time.fromSeconds 1) ;dummy_tac
       
   488                                               end)
       
   489 
       
   490 
       
   491 
   419 
   492 
   420 
   493 (* val proofstr = "1582[0:Inp] || -> v_P*.\
   421 (* val proofstr = "1582[0:Inp] || -> v_P*.\
   494                  \1583[0:Inp] || v_P* -> .\
   422                  \1583[0:Inp] || v_P* -> .\
   495 		 \1584[0:MRR:1583.0,1582.0] || -> ."; *)
   423 		 \1584[0:MRR:1583.0,1582.0] || -> ."; *)
   496 
   424 
   497 fun spassString_to_reconString proofstr thmstring goalstring toParent ppid thms clause_arr  num_of_clauses  = 
   425 fun spassString_to_reconString proofstr thmstring goalstring toParent ppid thms clause_arr  num_of_clauses  = 
   498       let val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "thmstringfile")));                                        
   426   let val _ = File.write(File.tmp_path (Path.basic "thmstringfile")) 
   499 	  (* val sign = sign_of_thm thm
   427                  (" thmstring is: "^thmstring^"proofstr is: "^proofstr)
   500 	 val prems = prems_of thm
   428       val tokens = #1(lex proofstr)
   501 	 val prems_string =  concat_with_and (map (Sign.string_of_term sign) prems) "" 
   429 
   502 	  val _ = warning ("thmstring is: "^thmstring);(*("thm in spassStrtoRec: "^(concat_with_and (map string_of_thm thms) "")^*)*)
   430   (***********************************)
   503 	  val _ = TextIO.output (outfile, (" thmstring is: "^thmstring^"proofstr is: "^proofstr))
   431   (* parse spass proof into datatype *)
   504 (*val _ = TextIO.output (outfile, (("in spassStrto Reconstr")));*)
   432   (***********************************)
   505 	  val _ =  TextIO.closeOut outfile
   433       val proof_steps1 = parse tokens
   506 
   434       val proof_steps = just_change_space proof_steps1
   507 	  val tokens = #1(lex proofstr)
   435 
   508 
   436       val _ = File.write (File.tmp_path (Path.basic "foo_parse"))
   509 	    
   437                       ("Did parsing on "^proofstr)
   510 
   438     
   511       (***********************************)
   439       val _ = File.write (File.tmp_path (Path.basic "foo_thmstring_at_parse"))
   512       (* parse spass proof into datatype *)
   440                                 ("Parsing for thmstring: "^thmstring)
   513       (***********************************)
   441   (************************************)
   514 
   442   (* recreate original subgoal as thm *)
   515 	  val proof_steps1 = parse tokens
   443   (************************************)
   516 	  val proof_steps = just_change_space proof_steps1
   444       (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
   517 
   445       (* need to get prems_of thm, then get right one of the prems, relating to whichever*)
   518 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_parse")));                                                                                          val _ = TextIO.output (outfile, ("Did parsing on "^proofstr))
   446       (* subgoal this is, and turn it into meta_clauses *)
   519 	  val _ =  TextIO.closeOut outfile
   447       (* should prob add array and table here, so that we can get axioms*)
       
   448       (* produced from the clasimpset rather than the problem *)
       
   449       val (frees,vars,extra_with_vars ,ax_with_vars,numcls) = get_axioms_used proof_steps  thms clause_arr  num_of_clauses
       
   450       
       
   451       (*val numcls_string = numclstr ( vars, numcls) ""*)
       
   452       val _ = File.write (File.tmp_path (Path.basic "foo_axiom")) "got axioms"
   520 	
   453 	
   521 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_thmstring_at_parse")));                                                                             val _ = TextIO.output (outfile, ("Parsing for thmstring: "^thmstring))
   454   (************************************)
   522 	  val _ =  TextIO.closeOut outfile
   455   (* translate proof                  *)
   523       (************************************)
   456   (************************************)
   524       (* recreate original subgoal as thm *)
   457       val _ = File.write (File.tmp_path (Path.basic "foo_steps"))                                                                           
   525       (************************************)
   458                        ("about to translate proof, steps: "
   526 	
   459                        ^(init_proofsteps_to_string proof_steps ""))
   527 	  (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
   460       val (newthm,proof) = translate_proof numcls  proof_steps vars
   528 	  (* need to get prems_of thm, then get right one of the prems, relating to whichever*)
   461       val _ = File.write (File.tmp_path (Path.basic "foo_steps2"))                                                                       
   529 	  (* subgoal this is, and turn it into meta_clauses *)
   462                        ("translated proof, steps: "^(init_proofsteps_to_string proof_steps ""))
   530 	  (* should prob add array and table here, so that we can get axioms*)
   463   (***************************************************)
   531 	  (* produced from the clasimpset rather than the problem *)
   464   (* transfer necessary steps as strings to Isabelle *)
   532 	  val (frees,vars,extra_with_vars ,ax_with_vars,numcls) = get_axioms_used proof_steps  thms clause_arr  num_of_clauses
   465   (***************************************************)
   533 	  
   466       (* turn the proof into a string *)
   534 	  (*val numcls_string = numclstr ( vars, numcls) ""*)
   467       val reconProofStr = proofs_to_string proof ""
   535 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_axiom")));                                                                            val _ = TextIO.output (outfile,"got axioms")
   468       (* do the bit for the Isabelle ordered axioms at the top *)
   536 	  val _ =  TextIO.closeOut outfile
   469       val ax_nums = map #1 numcls
   537 	    
   470       val ax_strs = map ReconOrderClauses.get_meta_lits_bracket (map #2 numcls)
   538       (************************************)
   471       val numcls_strs = ListPair.zip (ax_nums,ax_strs)
   539       (* translate proof                  *)
   472       val num_cls_vars =  map (addvars vars) numcls_strs;
   540       (************************************)
   473       val reconIsaAxStr = origAxs_to_string (ListPair.zip (ax_nums,ax_with_vars)) ""
   541 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_steps")));                                                          val _ = TextIO.output (outfile, ("about to translate proof, steps: "^(init_proofsteps_to_string proof_steps "")))
   474       
   542 	  val _ =  TextIO.closeOut outfile
   475       val extra_nums = if (not (extra_with_vars = [])) then (1 upto (length extra_with_vars))
   543 	  val (newthm,proof) = translate_proof numcls  proof_steps vars
   476                        else []
   544 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_steps2")));                                                                         val _ = TextIO.output (outfile, ("translated proof, steps: "^(init_proofsteps_to_string proof_steps "")))
   477       val reconExtraAxStr = extraAxs_to_string ( ListPair.zip (extra_nums,extra_with_vars)) ""
   545 	  val _ =  TextIO.closeOut outfile
   478       val frees_str = "["^(thmvars_to_string frees "")^"]"
   546       (***************************************************)
   479       val _ = File.write (File.tmp_path (Path.basic "reconstringfile"))
   547       (* transfer necessary steps as strings to Isabelle *)
   480                           (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
   548       (***************************************************)
   481       val reconstr = (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
   549 	  (* turn the proof into a string *)
   482   in 
   550 	  val reconProofStr = proofs_to_string proof ""
   483        TextIO.output (toParent, reconstr^"\n");
   551 	  (* do the bit for the Isabelle ordered axioms at the top *)
   484        TextIO.flushOut toParent;
   552 	  val ax_nums = map #1 numcls
   485        TextIO.output (toParent, thmstring^"\n");
   553 	  val ax_strs = map ReconOrderClauses.get_meta_lits_bracket (map #2 numcls)
   486        TextIO.flushOut toParent;
   554 	  val numcls_strs = ListPair.zip (ax_nums,ax_strs)
   487        TextIO.output (toParent, goalstring^"\n");
   555 	  val num_cls_vars =  map (addvars vars) numcls_strs;
   488        TextIO.flushOut toParent;
   556 	  val reconIsaAxStr = origAxs_to_string (ListPair.zip (ax_nums,ax_with_vars)) ""
   489 
   557 	  
   490        Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   558 	  val extra_nums = if (not (extra_with_vars = [])) then (1 upto (length extra_with_vars)) else []
   491       (* Attempt to prevent several signals from turning up simultaneously *)
   559 	  val reconExtraAxStr = extraAxs_to_string ( ListPair.zip (extra_nums,extra_with_vars)) ""
   492        Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
   560 	  val frees_str = "["^(thmvars_to_string frees "")^"]"
   493   end
   561 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "reconstringfile")));
   494   handle _ => 
   562 
   495   let val _ = File.write(File.tmp_path (Path.basic "foo_handler")) "In exception handler"
   563 	  val _ = TextIO.output (outfile, (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr))
   496   in 
   564 	  val _ =  TextIO.closeOut outfile
   497        TextIO.output (toParent,"Proof found but translation failed for resolution proof:"^(remove_linebreaks proofstr) ^"\n");
   565 	  val reconstr = (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
   498       TextIO.flushOut toParent;
   566       in 
   499     TextIO.output (toParent, thmstring^"\n");
   567 	   TextIO.output (toParent, reconstr^"\n");
   500        TextIO.flushOut toParent;
   568 	   TextIO.flushOut toParent;
   501        TextIO.output (toParent, goalstring^"\n");
   569 	   TextIO.output (toParent, thmstring^"\n");
   502        TextIO.flushOut toParent;
   570 	   TextIO.flushOut toParent;
   503       Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   571 	   TextIO.output (toParent, goalstring^"\n");
   504       (* Attempt to prevent several signals from turning up simultaneously *)
   572 	   TextIO.flushOut toParent;
   505       Posix.Process.sleep(Time.fromSeconds 1) ;dummy_tac
   573   
   506   end
   574 	   Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
       
   575 	  (* Attempt to prevent several signals from turning up simultaneously *)
       
   576 	   Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
       
   577       end
       
   578       handle _ => (let val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_handler")));
       
   579 
       
   580 	  val _ = TextIO.output (outfile, ("In exception handler"));
       
   581 	  val _ =  TextIO.closeOut outfile
       
   582       in 
       
   583 	   TextIO.output (toParent,"Proof found but translation failed for resolution proof:"^(remove_linebreaks proofstr) ^"\n");
       
   584 	  TextIO.flushOut toParent;
       
   585 	TextIO.output (toParent, thmstring^"\n");
       
   586 	   TextIO.flushOut toParent;
       
   587 	   TextIO.output (toParent, goalstring^"\n");
       
   588 	   TextIO.flushOut toParent;
       
   589 	  Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
       
   590 	  (* Attempt to prevent several signals from turning up simultaneously *)
       
   591 	  Posix.Process.sleep(Time.fromSeconds 1) ;dummy_tac
       
   592       end)
       
   593 
       
   594 
       
   595 
       
   596 
   507 
   597 
   508 
   598 (**********************************************************************************)
   509 (**********************************************************************************)
   599 (* At other end, want to turn back into datatype so can apply reconstruct_proof.  *)
   510 (* At other end, want to turn back into datatype so can apply reconstruct_proof.  *)
   600 (* This will be done by the signal handler                                        *)
   511 (* This will be done by the signal handler                                        *)
   887 		(assume_isar_origaxioms origaxioms)^
   798 		(assume_isar_origaxioms origaxioms)^
   888 		(isar_axiomlines axioms "")^
   799 		(isar_axiomlines axioms "")^
   889 		(isar_lines firststeps "")^
   800 		(isar_lines firststeps "")^
   890 		(last_isar_line laststep)^
   801 		(last_isar_line laststep)^
   891 		("qed")
   802 		("qed")
   892 	val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "isar_proof_file")));
   803 	val _ = File.write (File.tmp_path (Path.basic "isar_proof_file")) isar_proof
   893 	
       
   894 	val _ = TextIO.output (outfile, isar_proof)
       
   895 	val _ =  TextIO.closeOut outfile
       
   896     in
   804     in
   897 	isar_proof
   805 	isar_proof
   898     end;
   806     end;
   899 
   807 
   900 (* get fix vars from axioms - all Frees *)
   808 (* get fix vars from axioms - all Frees *)