src/HOL/Tools/ATP/recon_transfer_proof.ML
author wenzelm
Wed Jul 13 16:07:24 2005 +0200 (2005-07-13)
changeset 16803 014090d1e64b
parent 16548 aa36ae6b955e
child 16905 fa26952fa7b6
permissions -rw-r--r--
tuned;
     1 (*  ID:         $Id$
     2     Author:     Claire Quigley
     3     Copyright   2004  University of Cambridge
     4 *)
     5 
     6 (******************)
     7 (* complete later *)
     8 (******************)
     9 
    10 structure Recon_Transfer =
    11 struct
    12 
    13 open Recon_Parse
    14 
    15 infixr 8 ++; infixr 7 >>; infixr 6 ||;
    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 
    52 (* Versions that include type information *)
    53  
    54 (* FIXME rename to str_of_thm *)
    55 fun string_of_thm thm =
    56   setmp show_sorts true (Pretty.str_of o Display.pretty_thm) thm;
    57 
    58 
    59 (* check separate args in the watcher program for separating strings with a * or ; or something *)
    60 
    61 fun clause_strs_to_string [] str = str
    62 |   clause_strs_to_string (x::xs) str = clause_strs_to_string xs (str^x^"%")
    63 
    64 fun thmvars_to_string [] str = str
    65 |   thmvars_to_string (x::xs) str = thmvars_to_string xs (str^x^"%")
    66 
    67 
    68 fun proofstep_to_string Axiom = "Axiom()"
    69 |   proofstep_to_string  (Binary ((a,b), (c,d)))=
    70       "Binary(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"
    71 |   proofstep_to_string (Factor (a,b,c)) =
    72       "Factor("^(string_of_int a)^","^(string_of_int b)^","^(string_of_int c)^")"
    73 |   proofstep_to_string  (Para ((a,b), (c,d)))= 
    74       "Para(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"
    75 |   proofstep_to_string  (MRR ((a,b), (c,d))) =
    76       "MRR(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"
    77 (*|   proofstep_to_string (Rewrite((a,b),(c,d))) =
    78       "Rewrite(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"*)
    79 
    80 fun list_to_string [] liststr = liststr
    81 |   list_to_string (x::[]) liststr = liststr^(string_of_int x)
    82 |   list_to_string (x::xs) liststr = list_to_string xs (liststr^(string_of_int x)^",")
    83 
    84 
    85 fun proof_to_string (num,(step,clause_strs, thmvars)) = (string_of_int num)^(proofstep_to_string step)^"["^(clause_strs_to_string clause_strs "")^"]["^(thmvars_to_string thmvars "")^"]"
    86  
    87 
    88 fun proofs_to_string [] str = str
    89 |   proofs_to_string (x::xs) str = let val newstr = proof_to_string x 
    90                                    in
    91                                        proofs_to_string xs (str^newstr)
    92                                    end
    93 
    94 
    95 
    96 fun init_proofstep_to_string (num, step, clause_strs) = (string_of_int num)^" "^(proofstep_to_string step)^" "^(clause_strs_to_string clause_strs "")^" "
    97 
    98 fun init_proofsteps_to_string [] str = str
    99 |   init_proofsteps_to_string (x::xs) str = let val newstr = init_proofstep_to_string x 
   100                                    in
   101                                        init_proofsteps_to_string xs (str^newstr)
   102                                    end
   103   
   104 
   105 
   106 (*** get a string representing the Isabelle ordered axioms ***)
   107 
   108 fun origAx_to_string (num,(meta,thmvars)) =
   109     let val clause_strs = ReconOrderClauses.get_meta_lits_bracket meta
   110     in
   111        (string_of_int num)^"OrigAxiom()["^
   112        (clause_strs_to_string clause_strs "")^"]["^
   113        (thmvars_to_string thmvars "")^"]"
   114     end
   115 
   116 
   117 fun  origAxs_to_string [] str = str
   118 |   origAxs_to_string (x::xs) str = let val newstr = origAx_to_string x 
   119                                    in
   120                                        origAxs_to_string xs (str^newstr)
   121                                    end
   122 
   123 
   124 (*** get a string representing the Isabelle ordered axioms not used in the spass proof***)
   125 
   126 fun extraAx_to_string (num, (meta,thmvars)) =
   127    let val clause_strs = ReconOrderClauses.get_meta_lits_bracket meta
   128    in
   129       (string_of_int num)^"ExtraAxiom()["^
   130       (clause_strs_to_string clause_strs "")^"]"^
   131       "["^(thmvars_to_string thmvars "")^"]"
   132    end;
   133 
   134 fun extraAxs_to_string [] str = str
   135 |   extraAxs_to_string (x::xs) str =
   136       let val newstr = extraAx_to_string x 
   137       in
   138 	  extraAxs_to_string xs (str^newstr)
   139       end;
   140 
   141 fun is_axiom ( num:int,Axiom, str) = true
   142 |   is_axiom (num, _,_) = false
   143 
   144 fun get_init_axioms xs = List.filter (is_axiom) ( xs)
   145 
   146 fun get_step_nums [] nums = nums
   147 |   get_step_nums (( num:int,Axiom, str)::xs) nums = get_step_nums xs (nums@[num])
   148 
   149 exception Noassoc;
   150 
   151 fun assoc_snd a [] = raise Noassoc
   152   | assoc_snd a ((x, y)::t) = if a = y then x else assoc_snd a t;
   153 
   154 (* change to be something using check_order  instead of a = y --> returns true if ASSERTION not raised in checkorder, false otherwise *)
   155 
   156 (*fun get_assoc_snds [] xs assocs= assocs
   157 |   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_snd x ys))])
   158 *)
   159 (*FIX - should this have vars in it? *)
   160 fun there_out_of_order xs ys = (ReconOrderClauses.checkorder xs ys [] ([],[],[]); true) 
   161                                handle _ => false
   162 
   163 fun assoc_out_of_order a [] = raise Noassoc
   164 |   assoc_out_of_order a ((b,c)::t) = if there_out_of_order a c then b else assoc_out_of_order a t;
   165 
   166 fun get_assoc_snds [] xs assocs= assocs
   167 |   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_out_of_order x ys))])
   168 
   169 fun add_if_not_inlist [] xs newlist = newlist
   170 |   add_if_not_inlist (y::ys) xs newlist = if (not (y mem xs)) then 
   171                                       add_if_not_inlist ys xs (y::newlist)
   172                                         else add_if_not_inlist ys xs (newlist)
   173 
   174 (*Flattens a list of list of strings to one string*)
   175 fun onestr ls = String.concat (map String.concat ls);
   176 
   177 fun thmstrings [] str = str
   178 |   thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
   179 
   180 fun is_clasimp_ax clasimp_num n = n <=clasimp_num 
   181 
   182 
   183 
   184 fun retrieve_axioms clause_arr  [] = []
   185 |   retrieve_axioms clause_arr  (x::xs) =  [Array.sub(clause_arr, x)]@
   186  						     (retrieve_axioms clause_arr  xs)
   187 
   188 fun subone x = x - 1
   189 
   190 fun numstr [] = ""
   191 |   numstr (x::xs) = (string_of_int x)^"%"^(numstr xs)
   192 
   193 
   194 (* retrieve the axioms that were obtained from the clasimpset *)
   195 
   196 fun get_clasimp_cls clause_arr clasimp_num step_nums = 
   197     let val realnums = map subone step_nums	
   198 	val clasimp_nums = List.filter (is_clasimp_ax (clasimp_num - 1)) realnums
   199 (*	val axnums = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "axnums")))     
   200 	val _ = TextIO.output(axnums,(numstr clasimp_nums))
   201 	val _ = TextIO.closeOut(axnums)*)
   202     in
   203 	retrieve_axioms clause_arr  clasimp_nums
   204     end
   205 
   206 
   207 
   208 (*****************************************************)
   209 (* get names of clasimp axioms used                  *)
   210 (*****************************************************)
   211 
   212  fun get_axiom_names proof_steps thms (clause_arr:(ResClause.clause * thm) Array.array) num_of_clauses  =
   213    let 
   214      (* not sure why this is necessary again, but seems to be *)
   215       val _ = (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   216       val axioms = get_init_axioms proof_steps
   217       val step_nums = get_step_nums axioms []
   218   
   219      (***********************************************)
   220      (* here need to add the clauses from clause_arr*)
   221      (***********************************************)
   222   
   223       val (clasimp_names_cls) = get_clasimp_cls clause_arr num_of_clauses step_nums 
   224       val clasimp_names = map (#1 o ResClause.clause_info o #1) clasimp_names_cls
   225   
   226       val _ = File.write (File.tmp_path (Path.basic "clasimp_names"))                                                               
   227                          (concat clasimp_names)
   228       val _ = (print_mode := (["xsymbols", "symbols"] @ ! print_mode))
   229    in
   230       clasimp_names
   231    end
   232     
   233  fun get_axiom_names_vamp proofstr thms (clause_arr:(ResClause.clause * thm) Array.array) num_of_clauses  =
   234    let 
   235      (* not sure why this is necessary again, but seems to be *)
   236       val _ = (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   237       val step_nums =get_linenums proofstr
   238   
   239      (***********************************************)
   240      (* here need to add the clauses from clause_arr*)
   241      (***********************************************)
   242   
   243       val (clasimp_names_cls) = get_clasimp_cls clause_arr num_of_clauses step_nums 
   244       val clasimp_names = map (#1 o ResClause.clause_info o #1) clasimp_names_cls
   245   
   246       val _ = File.write (File.tmp_path (Path.basic "clasimp_names"))                                                               
   247                          (concat clasimp_names)
   248       val _ = (print_mode := (["xsymbols", "symbols"] @ ! print_mode))
   249    in
   250       clasimp_names
   251    end
   252     
   253 
   254 
   255 
   256 (***********************************************)
   257 (* get axioms for reconstruction               *)
   258 (***********************************************)
   259 fun numclstr (vars, []) str = str
   260 |   numclstr ( vars, ((num, thm)::rest)) str =
   261       let val newstr = str^(string_of_int num)^" "^(string_of_thm thm)^" "
   262       in
   263         numclstr  (vars,rest) newstr
   264       end
   265 
   266 fun addvars c (a,b)  = (a,b,c)
   267 
   268  fun get_axioms_used proof_steps thms clause_arr num_of_clauses  =
   269      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"])))
   277 	val axioms = get_init_axioms proof_steps
   278 	val step_nums = get_step_nums axioms []
   279 
   280        (***********************************************)
   281        (* here need to add the clauses from clause_arr*)
   282        (***********************************************)
   283 
   284        (* val clasimp_names_cls = get_clasimp_cls clause_arr   num_of_clauses step_nums   
   285 	val clasimp_names = map #1 clasimp_names_cls
   286 	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                            
   288 	 val _ = TextIO.output (outfile,clasimp_namestr)
   289 	 
   290 	 val _ =  TextIO.closeOut outfile
   291 *)
   292 
   293 	val clauses =(*(clasimp_cls)@*)( make_clauses thms)
   294 	
   295 	val vars = map thm_vars clauses
   296        
   297 	val distvars = distinct (fold append vars [])
   298 	val clause_terms = map prop_of clauses  
   299 	val clause_frees = List.concat (map term_frees clause_terms)
   300 
   301 	val frees = map lit_string_with_nums clause_frees;
   302 
   303 	val distfrees = distinct frees
   304 
   305 	val metas = map Meson.make_meta_clause clauses
   306 	val ax_strs = map #3 axioms
   307 
   308 	(* literals of -all- axioms, not just those used by spass *)
   309 	val meta_strs = map ReconOrderClauses.get_meta_lits metas
   310        
   311 	val metas_and_strs = ListPair.zip (metas,meta_strs)
   312 	 val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_clauses")));                                                                       
   313 	 val _ = TextIO.output (outfile, onestr ax_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 
   320 	(* get list of axioms as thms with their variables *)
   321 
   322 	val ax_metas = get_assoc_snds ax_strs metas_and_strs []
   323 	val ax_vars = map thm_vars ax_metas
   324 	val ax_with_vars = ListPair.zip (ax_metas,ax_vars)
   325 
   326 	(* get list of extra axioms as thms with their variables *)
   327 	val extra_metas = add_if_not_inlist metas ax_metas []
   328 	val extra_vars = map thm_vars extra_metas
   329 	val extra_with_vars = if (not (extra_metas = []) ) 
   330 			      then
   331 				     ListPair.zip (extra_metas,extra_vars)
   332 			      else
   333 				     []
   334 
   335        (* 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")))
   337 
   338        val _ = TextIO.output (outfile, ((thmstrings ax_metas "")))
   339        val _ =  TextIO.closeOut outfile
   340       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"))
   342 	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")))
   344     val ax_metas_str = TextIO.inputLine (infile)
   345     val _ = TextIO.closeIn infile
   346        val _= (print_mode := (["xsymbols", "symbols"] @ ! print_mode))*)
   347        
   348      in
   349 	(distfrees,distvars, extra_with_vars,ax_with_vars, (*clasimp_names*)(ListPair.zip (step_nums,ax_metas)))
   350      end
   351     
   352 
   353                                         
   354 
   355 (*********************************************************************)
   356 (* 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   *)
   358 (*********************************************************************)
   359 
   360 
   361 fun rules_to_string [] str = str
   362 |   rules_to_string [x] str = str^x
   363 |   rules_to_string (x::xs) str = rules_to_string xs (str^x^"   ")
   364                                   
   365 
   366 val dummy_tac = PRIMITIVE(fn thm => thm );
   367 
   368 
   369 (*val  proofstr = "1242[0:Inp] ||  -> equal(const_List_Orev(tconst_fun(tconst_List_Olist(U),tconst_List_Olist(U)),const_List_Olist_ONil),const_List_Olist_ONil)**.\
   370 \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))** -> .\
   372 \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] ||  -> .";*)
   374 
   375 fun subst_for a b [] = ""
   376   | subst_for a b (x :: xs) =
   377       if x = a
   378       then 
   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 
   387 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")));          
   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)))
   390 
   391               	val _ =  TextIO.closeOut outfile
   392 
   393                  (***********************************)
   394                  (* parse spass proof into datatype *)
   395                  (***********************************)
   396          
   397                   val tokens = #1(lex proofstr)
   398                   val proof_steps1 = parse tokens
   399                   val proof_steps = just_change_space proof_steps1
   400                   val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_parse")));        val _ = TextIO.output (outfile, ("Did parsing on "^proofstr))
   401                                                   val _ =  TextIO.closeOut outfile
   402                                                 
   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))
   404                                                   val _ =  TextIO.closeOut outfile
   405                                               (************************************)
   406                                               (* recreate original subgoal as thm *)
   407                                               (************************************)
   408                                                 
   409                                                   (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
   410                                                   (* need to get prems_of thm, then get right one of the prems, relating to whichever*)
   411                                                   (* subgoal this is, and turn it into meta_clauses *)
   412                                                   (* should prob add array and table here, so that we can get axioms*)
   413                                                   (* produced from the clasimpset rather than the problem *)
   414 
   415                                                   val (axiom_names) = get_axiom_names proof_steps  thms clause_arr  num_of_clauses
   416                                                   val ax_str = "Rules from clasimpset used in proof found by SPASS: "^(rules_to_string axiom_names "")
   417                                                   val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "reconstrfile")));                                                     val _ = TextIO.output (outfile, ("reconstring is: "^ax_str^"  "^goalstring))
   418                                                   val _ =  TextIO.closeOut outfile
   419                                                    
   420                                               in 
   421                                                    TextIO.output (toParent, ax_str^"\n");
   422                                                    TextIO.flushOut toParent;
   423                                         	   TextIO.output (toParent, "goalstring: "^goalstring^"\n");
   424                                          	   TextIO.flushOut toParent;
   425                                          	   TextIO.output (toParent, "thmstring: "^thmstring^"\n");
   426                                          	   TextIO.flushOut toParent;
   427                                           
   428                                          	   Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   429                                          	  (* Attempt to prevent several signals from turning up simultaneously *)
   430                                          	   Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
   431                                               end
   432                                               handle _ => (let val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_handler")));
   433 
   434                                                   val _ = TextIO.output (outfile, ("In exception handler"));
   435                                                   val _ =  TextIO.closeOut outfile
   436                                               in 
   437                                                  TextIO.output (toParent,"Proof found but parsing failed for resolution proof: "^(remove_linebreaks proofstr)^"\n" );
   438                                                   TextIO.flushOut toParent;
   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 
   448 
   449 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)))
   451                                                val _ =  TextIO.closeOut outfile
   452 
   453                                               (***********************************)
   454                                               (* get vampire axiom names         *)
   455                                               (***********************************)
   456          
   457                                                val (axiom_names) = get_axiom_names_vamp proofstr  thms clause_arr  num_of_clauses
   458                                                val ax_str = "Rules from clasimpset used in proof found by Vampire: "^(rules_to_string axiom_names "")
   459                                                val  outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "reconstrfile")));                                                    val _ = TextIO.output (outfile, ("reconstring is: "^ax_str^"  "^goalstring))
   460                                                val _ =  TextIO.closeOut outfile
   461                                                    
   462                                               in 
   463                                                    TextIO.output (toParent, ax_str^"\n");
   464                                                    TextIO.flushOut toParent;
   465                                         	   TextIO.output (toParent, "goalstring: "^goalstring^"\n");
   466                                          	   TextIO.flushOut toParent;
   467                                          	   TextIO.output (toParent, "thmstring: "^thmstring^"\n");
   468                                          	   TextIO.flushOut toParent;
   469                                           
   470                                          	   Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   471                                          	  (* Attempt to prevent several signals from turning up simultaneously *)
   472                                          	   Posix.Process.sleep(Time.fromSeconds 1) ; dummy_tac
   473                                               end
   474                                               handle _ => (let val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_handler")));
   475 
   476                                                   val _ = TextIO.output (outfile, ("In exception handler"));
   477                                                   val _ =  TextIO.closeOut outfile
   478                                               in 
   479                                                   TextIO.output (toParent,"Proof found by Vampire but translation failed for resolution proof: "^(remove_linebreaks proofstr) );
   480                                                   TextIO.flushOut toParent;
   481 						   TextIO.output (toParent, thmstring^"\n");
   482                                          	   TextIO.flushOut toParent;
   483                                          	   TextIO.output (toParent, goalstring^"\n");
   484                                          	   TextIO.flushOut toParent;
   485             					  Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
   486                                          	  (* Attempt to prevent several signals from turning up simultaneously *)
   487                                          	  Posix.Process.sleep(Time.fromSeconds 1) ;dummy_tac
   488                                               end)
   489 
   490 
   491 
   492 
   493 (* val proofstr = "1582[0:Inp] || -> v_P*.\
   494                  \1583[0:Inp] || v_P* -> .\
   495 		 \1584[0:MRR:1583.0,1582.0] || -> ."; *)
   496 
   497 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")));                                        
   499 	  (* val sign = sign_of_thm thm
   500 	 val prems = prems_of thm
   501 	 val prems_string =  concat_with_and (map (Sign.string_of_term sign) prems) "" 
   502 	  val _ = warning ("thmstring is: "^thmstring);(*("thm in spassStrtoRec: "^(concat_with_and (map string_of_thm thms) "")^*)*)
   503 	  val _ = TextIO.output (outfile, (" thmstring is: "^thmstring^"proofstr is: "^proofstr))
   504 (*val _ = TextIO.output (outfile, (("in spassStrto Reconstr")));*)
   505 	  val _ =  TextIO.closeOut outfile
   506 
   507 	  val tokens = #1(lex proofstr)
   508 
   509 	    
   510 
   511       (***********************************)
   512       (* parse spass proof into datatype *)
   513       (***********************************)
   514 
   515 	  val proof_steps1 = parse tokens
   516 	  val proof_steps = just_change_space proof_steps1
   517 
   518 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_parse")));                                                                                          val _ = TextIO.output (outfile, ("Did parsing on "^proofstr))
   519 	  val _ =  TextIO.closeOut outfile
   520 	
   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))
   522 	  val _ =  TextIO.closeOut outfile
   523       (************************************)
   524       (* recreate original subgoal as thm *)
   525       (************************************)
   526 	
   527 	  (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
   528 	  (* need to get prems_of thm, then get right one of the prems, relating to whichever*)
   529 	  (* subgoal this is, and turn it into meta_clauses *)
   530 	  (* should prob add array and table here, so that we can get axioms*)
   531 	  (* produced from the clasimpset rather than the problem *)
   532 	  val (frees,vars,extra_with_vars ,ax_with_vars,numcls) = get_axioms_used proof_steps  thms clause_arr  num_of_clauses
   533 	  
   534 	  (*val numcls_string = numclstr ( vars, numcls) ""*)
   535 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_axiom")));                                                                            val _ = TextIO.output (outfile,"got axioms")
   536 	  val _ =  TextIO.closeOut outfile
   537 	    
   538       (************************************)
   539       (* translate proof                  *)
   540       (************************************)
   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 "")))
   542 	  val _ =  TextIO.closeOut outfile
   543 	  val (newthm,proof) = translate_proof numcls  proof_steps vars
   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 "")))
   545 	  val _ =  TextIO.closeOut outfile
   546       (***************************************************)
   547       (* transfer necessary steps as strings to Isabelle *)
   548       (***************************************************)
   549 	  (* turn the proof into a string *)
   550 	  val reconProofStr = proofs_to_string proof ""
   551 	  (* do the bit for the Isabelle ordered axioms at the top *)
   552 	  val ax_nums = map #1 numcls
   553 	  val ax_strs = map ReconOrderClauses.get_meta_lits_bracket (map #2 numcls)
   554 	  val numcls_strs = ListPair.zip (ax_nums,ax_strs)
   555 	  val num_cls_vars =  map (addvars vars) numcls_strs;
   556 	  val reconIsaAxStr = origAxs_to_string (ListPair.zip (ax_nums,ax_with_vars)) ""
   557 	  
   558 	  val extra_nums = if (not (extra_with_vars = [])) then (1 upto (length extra_with_vars)) else []
   559 	  val reconExtraAxStr = extraAxs_to_string ( ListPair.zip (extra_nums,extra_with_vars)) ""
   560 	  val frees_str = "["^(thmvars_to_string frees "")^"]"
   561 	  val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "reconstringfile")));
   562 
   563 	  val _ = TextIO.output (outfile, (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr))
   564 	  val _ =  TextIO.closeOut outfile
   565 	  val reconstr = (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
   566       in 
   567 	   TextIO.output (toParent, reconstr^"\n");
   568 	   TextIO.flushOut toParent;
   569 	   TextIO.output (toParent, thmstring^"\n");
   570 	   TextIO.flushOut toParent;
   571 	   TextIO.output (toParent, goalstring^"\n");
   572 	   TextIO.flushOut toParent;
   573   
   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 
   597 
   598 (**********************************************************************************)
   599 (* At other end, want to turn back into datatype so can apply reconstruct_proof.  *)
   600 (* This will be done by the signal handler                                        *)
   601 (**********************************************************************************)
   602 
   603 (* Parse in the string version of the proof steps for reconstruction *)
   604 (* Isar format: cl1 [BINARY 0 cl2 0];cl1 [PARAMOD 0 cl2 0]; cl1 [DEMOD 0 cl2];cl1 [FACTOR 1 2];*)
   605 
   606 
   607  val term_numstep =
   608         (number ++ (a (Other ",")) ++ number) >> (fn (a, (_, c)) => (a, c))
   609 
   610 val extraaxiomstep = (a (Word "ExtraAxiom"))++ (a (Other "(")) ++(a (Other ")"))
   611             >> (fn (_) => ExtraAxiom)
   612 
   613 
   614 
   615 val origaxiomstep = (a (Word "OrigAxiom"))++ (a (Other "(")) ++(a (Other ")"))
   616             >> (fn (_) => OrigAxiom)
   617 
   618 
   619  val axiomstep = (a (Word "Axiom"))++ (a (Other "(")) ++(a (Other ")"))
   620             >> (fn (_) => Axiom)
   621      
   622 
   623 
   624       
   625  val binarystep = (a (Word "Binary")) ++ (a (Other "(")) ++ (a (Other "(")) 
   626                    ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   627                    ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   628             >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Binary (c,e))
   629       
   630 
   631  val parastep = (a (Word "Para")) ++ (a (Other "(")) ++ (a (Other "(")) 
   632                    ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   633                    ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   634             >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Para(c, e))
   635       
   636  val mrrstep = (a (Word "MRR")) ++ (a (Other "(")) ++ (a (Other "(")) 
   637                    ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   638                    ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   639             >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => MRR(c, e))
   640       
   641 
   642  val factorstep = (a (Word "Factor")) ++ (a (Other "("))
   643                     ++ number ++ (a (Other ","))
   644                        ++ number ++ (a (Other ","))
   645                        ++ number ++  (a (Other ")"))
   646                    
   647             >> (fn (_, (_, (c, (_, (e,(_,(f,_))))))) =>  Factor (c,e,f))
   648 
   649 
   650 (*val rewritestep = (a (Word "Rewrite"))  ++ (a (Other "(")) ++ (a (Other "(")) 
   651                    ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   652                    ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   653             >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Rewrite (c,e))*)
   654 
   655 val obviousstep = (a (Word "Obvious")) ++ (a (Other "(")) 
   656                    ++ term_numstep  ++ (a (Other ")")) 
   657             >> (fn (_, (_, (c,_))) => Obvious (c))
   658 
   659  val methodstep = extraaxiomstep || origaxiomstep || axiomstep ||binarystep || factorstep|| parastep || mrrstep || (*rewritestep ||*) obviousstep
   660 
   661 
   662  val number_list_step =
   663         ( number ++ many ((a (Other ",") ++ number)>> #2))
   664         >> (fn (a,b) => (a::b))
   665         
   666  val numberlist_step = a (Other "[")  ++ a (Other "]")
   667                         >>(fn (_,_) => ([]:int list))
   668                        || a (Other "[") ++ number_list_step ++ a (Other "]")
   669                         >>(fn (_,(a,_)) => a)
   670                     
   671 
   672 
   673 (** change this to allow P (x U) *)
   674  fun arglist_step input = ( word ++ many  word >> (fn (a, b) => (a^" "^(implode_with_space b)))
   675                            ||word >> (fn (a) => (a)))input
   676                 
   677 
   678 fun literal_step input = (word ++ a (Other "(") ++ arglist_step ++  a (Other ")")
   679                                           >>(fn (a, (b, (c,d))) => (a^" ("^(c)^")"))
   680                         || arglist_step >> (fn (a) => (a)))input
   681                            
   682 
   683 
   684 (* fun term_step input = (a (Other "~") ++ arglist_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
   685                      ||  arglist_step ++ a (Other "%")>> (fn (a,b) => a ))input
   686 *)
   687 
   688 
   689  fun term_step input = (a (Other "~") ++ literal_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
   690                      ||  literal_step ++ a (Other "%")>> (fn (a,b) => a ))input
   691 
   692 
   693          
   694 
   695  val term_list_step =
   696         (  term_step ++ many ( term_step))
   697         >> (fn (a,b) => (a::b))
   698         
   699  
   700 val term_lists_step = a (Other "[")  ++ a (Other "]")
   701                         >>(fn (_,_) => ([]:string list))
   702                        || a (Other "[") ++ term_list_step ++ a (Other "]")
   703                         >>(fn (_,(a,_)) => a)
   704                      
   705 
   706 
   707 
   708 fun anytoken_step input  = (word>> (fn (a) => a)  ) input
   709                        handle NOPARSE_WORD => (number>> (fn (a) => string_of_int a)  ) input
   710                       handle NOPARSE_NUMBER => (other_char >> (fn(a) => a)) input
   711 
   712 
   713 
   714 fun goalstring_step input= (anytoken_step ++ many (anytoken_step )
   715                   >> (fn (a,b) =>  (a^" "^(implode b)))) input
   716 
   717 
   718 
   719  val linestep = number ++ methodstep ++ term_lists_step ++ term_lists_step
   720                 >> (fn (a, (b, (c,d))) => (a,(b,c,d)))
   721     
   722  val lines_step = many linestep
   723 
   724  val alllines_step = (term_lists_step ++ lines_step ) ++ finished >> #1
   725     
   726  val parse_step = #1 o alllines_step
   727 
   728 
   729  (*
   730 val reconstr ="[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]%(EX x::'a::type. ALL y::'a::type. (P::'a::type => bool) x = P y) -->(EX x::'a::type. P x) = (ALL y::'a::type. P y)"
   731 *)
   732 
   733 (************************************************************)
   734 (* Construct an Isar style proof from a list of proof steps *)
   735 (************************************************************)
   736 (* want to assume all axioms, then do haves for the other clauses*)
   737 (* then show for the last step *)
   738 
   739 (* replace ~ by not here *)
   740 fun change_nots [] = []
   741 |   change_nots (x::xs) = if x = "~" 
   742                           then 
   743                              ["\\", "<", "n", "o", "t", ">"]@(change_nots xs)
   744                           else (x::(change_nots xs))
   745 
   746 (*
   747 fun clstrs_to_string [] str = str
   748 |   clstrs_to_string (x::[]) str = str^x
   749 |   clstrs_to_string (x::xs) str = clstrs_to_string xs (str^(x^"; "))
   750 *)
   751 fun clstrs_to_string [] str = implode (change_nots (explode str))
   752 |   clstrs_to_string (x::[]) str = implode (change_nots (explode (str^x)))
   753 |   clstrs_to_string (x::xs) str = implode (change_nots (explode (clstrs_to_string xs (str^(x^"; ")))))
   754 
   755 
   756 
   757 fun thmvars_to_quantstring [] str = str
   758 |   thmvars_to_quantstring (x::[]) str =str^x^". "
   759 |   thmvars_to_quantstring (x::xs) str = thmvars_to_quantstring xs (str^(x^" "))
   760 
   761 
   762 fun clause_strs_to_isar clstrs [] =  "\"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> \\<Longrightarrow> False\""
   763 |   clause_strs_to_isar clstrs thmvars = "\"\\<And>"^(thmvars_to_quantstring thmvars "")^"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> \\<Longrightarrow> False\""
   764 
   765 fun frees_to_string [] str = implode (change_nots (explode str))
   766 |   frees_to_string (x::[]) str = implode (change_nots (explode (str^x)))
   767 |   frees_to_string  (x::xs) str = implode (change_nots (explode (frees_to_string xs (str^(x^" ")))))
   768 
   769 fun frees_to_isar_str [] =  ""
   770 |   frees_to_isar_str  clstrs = (frees_to_string clstrs "")
   771 
   772 
   773 (***********************************************************************)
   774 (* functions for producing assumptions for the Isabelle ordered axioms *)
   775 (***********************************************************************)
   776 (*val str = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";       
   777 num, rule, clausestrs, vars*)
   778 
   779 
   780 (* assume the extra clauses - not used in Spass proof *)
   781 
   782 fun is_extraaxiom_step ( num:int,(ExtraAxiom, str, tstr)) = true
   783 |   is_extraaxiom_step (num, _) = false
   784 
   785 fun get_extraaxioms xs = List.filter (is_extraaxiom_step) ( xs)
   786 
   787 fun assume_isar_extraaxiom [] str  = str
   788 |   assume_isar_extraaxiom ((numb,(step, clstr, thmvars))::xs) str  = assume_isar_extraaxiom xs (str^"and cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstr thmvars)^"\n " )
   789 
   790 
   791 
   792 fun assume_isar_extraaxioms  [] = ""
   793 |assume_isar_extraaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n" 
   794                                          in
   795                                              assume_isar_extraaxiom xs str
   796                                          end
   797 
   798 (* assume the Isabelle ordered clauses *)
   799 
   800 fun is_origaxiom_step ( num:int,(OrigAxiom, str, tstr)) = true
   801 |   is_origaxiom_step (num, _) = false
   802 
   803 fun get_origaxioms xs = List.filter (is_origaxiom_step) ( xs)
   804 
   805 fun assume_isar_origaxiom [] str  = str
   806 |   assume_isar_origaxiom ((numb,(step, clstr, thmvars))::xs) str  = assume_isar_origaxiom xs (str^"and cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstr thmvars)^"\n " )
   807 
   808 
   809 
   810 fun assume_isar_origaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n" 
   811                                          in
   812                                              assume_isar_origaxiom xs str
   813                                          end
   814 
   815 
   816 
   817 fun is_axiom_step ( num:int,(Axiom, str, tstr)) = true
   818 |   is_axiom_step (num, _) = false
   819 
   820 fun get_axioms xs = List.filter  (is_axiom_step) ( xs)
   821 
   822 fun have_isar_axiomline (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
   823 
   824 fun  by_isar_axiomline (numb,(step, clstrs, thmstrs))="by (rule cl"^ (string_of_int numb)^"') \n"
   825 
   826 
   827 fun isar_axiomline (numb, (step, clstrs, thmstrs))  = (have_isar_axiomline (numb,(step,clstrs, thmstrs )))^( by_isar_axiomline(numb,(step,clstrs, thmstrs )) )
   828 
   829 
   830 fun isar_axiomlines [] str = str
   831 |   isar_axiomlines (x::xs) str = isar_axiomlines xs (str^(isar_axiomline x))
   832 
   833 
   834 fun have_isar_line (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
   835 (*FIX: ask Larry to add and mrr attribute *)
   836 
   837 fun by_isar_line ((Binary ((a,b), (c,d)))) = 
   838     "by(rule cl"^
   839 		(string_of_int a)^" [binary "^(string_of_int b)^" cl"^
   840 		(string_of_int c)^" "^(string_of_int d)^"])\n"
   841 |by_isar_line ((MRR ((a,b), (c,d)))) = 
   842     "by(rule cl"^
   843 		(string_of_int a)^" [binary "^(string_of_int b)^" cl"^
   844 		(string_of_int c)^" "^(string_of_int d)^"])\n"
   845 |   by_isar_line ( (Para ((a,b), (c,d)))) =
   846     "by (rule cl"^
   847 		(string_of_int a)^" [paramod "^(string_of_int b)^" cl"^
   848 		(string_of_int c)^" "^(string_of_int d)^"])\n"
   849 |   by_isar_line ((Factor ((a,b,c)))) = 
   850     "by (rule cl"^(string_of_int a)^" [factor "^(string_of_int b)^" "^
   851 		(string_of_int c)^" ])\n"
   852 (*|   by_isar_line ( (Rewrite ((a,b),(c,d)))) =
   853     "by (rule cl"^(string_of_int a)^" [demod "^(string_of_int b)^" "^
   854 		(string_of_int c)^" "^(string_of_int d)^" ])\n"*)
   855 |   by_isar_line ( (Obvious ((a,b)))) =
   856     "by (rule cl"^(string_of_int a)^" [obvious "^(string_of_int b)^" ])\n"
   857 
   858 fun isar_line (numb, (step, clstrs, thmstrs))  = (have_isar_line (numb,(step,clstrs, thmstrs )))^( by_isar_line step)
   859 
   860 
   861 fun isar_lines [] str = str
   862 |   isar_lines (x::xs) str = isar_lines xs (str^(isar_line x))
   863 
   864 fun last_isar_line (numb,( step, clstrs,thmstrs)) = "show \"False\"\n"^(by_isar_line step)
   865 
   866 
   867 fun to_isar_proof (frees, xs, goalstring) =
   868     let val extraaxioms = get_extraaxioms xs
   869 	val extraax_num = length extraaxioms
   870 	val origaxioms_and_steps = Library.drop (extraax_num, xs)  
   871 	
   872 	val origaxioms = get_origaxioms origaxioms_and_steps
   873 	val origax_num = length origaxioms
   874 	val axioms_and_steps = Library.drop (origax_num + extraax_num, xs)  
   875 	val axioms = get_axioms axioms_and_steps
   876 	
   877 	val steps = Library.drop (origax_num, axioms_and_steps)
   878 	val firststeps = ReconOrderClauses.butlast steps
   879 	val laststep = ReconOrderClauses.last steps
   880 	val goalstring = implode(ReconOrderClauses.butlast(explode goalstring))
   881 	
   882 	val isar_proof = 
   883 		("show \""^goalstring^"\"\n")^
   884 		("proof (rule ccontr,skolemize, make_clauses) \n")^
   885 		("fix "^(frees_to_isar_str frees)^"\n")^
   886 		(assume_isar_extraaxioms extraaxioms)^
   887 		(assume_isar_origaxioms origaxioms)^
   888 		(isar_axiomlines axioms "")^
   889 		(isar_lines firststeps "")^
   890 		(last_isar_line laststep)^
   891 		("qed")
   892 	val  outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "isar_proof_file")));
   893 	
   894 	val _ = TextIO.output (outfile, isar_proof)
   895 	val _ =  TextIO.closeOut outfile
   896     in
   897 	isar_proof
   898     end;
   899 
   900 (* get fix vars from axioms - all Frees *)
   901 (* check each clause for meta-vars and /\ over them at each step*)
   902 
   903 (*******************************************************)
   904 (* This assumes the thm list  "numcls" is still there  *)
   905 (* In reality, should probably label it with an        *)
   906 (* ID number identifying the subgoal.  This could      *)
   907 (* be passed over to the watcher, e.g.  numcls25       *)
   908 (*******************************************************)
   909 
   910 (* val str = "[S%x%P%R%Q%]1ExtraAxiom()[~ Q U%~ R U%][U%]2ExtraAxiom()[~ Q U%~ P U%][U%]3ExtraAxiom()[Q U%R U%][U%]1OrigAxiom()[S x%][]2OrigAxiom()[P U%R U%][U%]6OrigAxiom()[~ S U%~ P U%][U%]7OrigAxiom()[~ S U%~ R U%][U%]1Axiom()[S x%][]2Axiom()[R U%P U%][U%]6Axiom()[~ P U%~ S U%][U%]7Axiom()[~ R U%~ S U%][U%]8Binary((6,1),(1,0))[~ P x%][]9Binary((7,1),(1,0))[~ R x%][]19Binary((9,0),(2,0))[P x%][]25Binary((8,0),(19,0))[][]";
   911 
   912 val str = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";
   913 
   914 val reconstr = "[P%Q%x%xa%]1OrigAxiom()[~ P U%][U%]3OrigAxiom()[Q U%][U%]5OrigAxiom()[P (x U)%~ Q (xa U)%][U%]9Binary((7,0),(3,0))[][]7Binary((1,0),(5,0))[~ Q (xa U)%][U%]5Axiom()[P (x U)%~ Q (xa U)%][U%]3Axiom()[Q U%][U%]1Axiom()[~ P U%][U%](ALL xb::'a::type.   (~ (P::'a::type => bool) ((x::'a::type => 'a::type) xb) |    (Q::'a::type => bool) ((xa::'a::type => 'a::type) xb)) &   P xb & ~ Q xb)";
   915 
   916 
   917 val reconstr = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";
   918 
   919 val thmstring = " (ALL xa::'a::type.   (~ (P::'a::type => bool) (x::'a::type) | P xa) & (~ P xa | P x)) & (((P::'a::type => bool) (xa::'a::type) | (ALL x::'a::type. P x)) &((ALL x::'a::type. ~ P x) | ~ P (xb::'a::type)))";
   920 *)
   921 
   922 fun apply_res_thm str goalstring  = let val tokens = #1 (lex str);
   923 				val _ = File.append (File.tmp_path (Path.basic "applyres")) 
   924 			           ("str is: "^str^" goalstr is: "^goalstring^"\n")	
   925                                    val (frees,recon_steps) = parse_step tokens 
   926                                    val isar_str = to_isar_proof (frees, recon_steps, goalstring)
   927                                    val foo =   TextIO.openOut (File.platform_path(File.tmp_path (Path.basic "foobar")));
   928                                in 
   929                                   TextIO.output(foo,(isar_str));TextIO.closeOut foo;Pretty.writeln(Pretty.str  isar_str); () 
   930                                end 
   931 
   932 
   933 (* val reconstr = reconstr^"[P%]51Axiom()[~P%]52Axiom[P%][]53MRR((52,0),(51,0))[][]";
   934 *)
   935 end;