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