src/HOL/Tools/ATP/recon_transfer_proof.ML
changeset 15642 028059faa963
child 15658 2edb384bf61f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Tools/ATP/recon_transfer_proof.ML	Thu Mar 31 19:29:26 2005 +0200
     1.3 @@ -0,0 +1,809 @@
     1.4 +(******************)
     1.5 +(* complete later *)
     1.6 +(******************)
     1.7 +
     1.8 +fun not_newline ch = not (ch = "\n");
     1.9 +
    1.10 +
    1.11 +
    1.12 +(* Versions that include type information *)
    1.13 + 
    1.14 +fun string_of_thm thm = let val _ = set show_sorts
    1.15 +                                val str = Sign.string_of_term Mainsign (prop_of thm)
    1.16 +                                val no_returns =List.filter not_newline (explode str)
    1.17 +                                val _ = reset show_sorts
    1.18 +                            in 
    1.19 +                                implode no_returns
    1.20 +                            end
    1.21 +
    1.22 +
    1.23 +fun thm_of_string str = let val _ = set show_sorts
    1.24 +                                val term = read str
    1.25 +                                val propterm = mk_Trueprop term
    1.26 +                                val cterm = cterm_of Mainsign propterm
    1.27 +                                val _ = reset show_sorts
    1.28 +                            in
    1.29 +                                assume cterm
    1.30 +                            end
    1.31 +
    1.32 +(* check separate args in the watcher program for separating strings with a * or ; or something *)
    1.33 +
    1.34 +fun clause_strs_to_string [] str = str
    1.35 +|   clause_strs_to_string (x::xs) str = clause_strs_to_string xs (str^x^"%")
    1.36 +
    1.37 +
    1.38 +
    1.39 +fun thmvars_to_string [] str = str
    1.40 +|   thmvars_to_string (x::xs) str = thmvars_to_string xs (str^x^"%")
    1.41 +
    1.42 +
    1.43 +fun proofstep_to_string Axiom = "Axiom()"
    1.44 +|   proofstep_to_string  (Binary ((a,b), (c,d)))= "Binary"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
    1.45 +|   proofstep_to_string (Factor (a,b,c)) = "Factor"^"("^(string_of_int a)^","^(string_of_int b)^","^(string_of_int c)^")"
    1.46 +|   proofstep_to_string  (Para ((a,b), (c,d)))= "Para"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
    1.47 +|   proofstep_to_string  (MRR ((a,b), (c,d)))= "MRR"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
    1.48 +|   proofstep_to_string (Rewrite((a,b),(c,d))) = "Rewrite"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
    1.49 +
    1.50 +fun list_to_string [] liststr = liststr
    1.51 +|   list_to_string (x::[]) liststr = liststr^(string_of_int x)
    1.52 +|   list_to_string (x::xs) liststr = list_to_string xs (liststr^(string_of_int x)^",")
    1.53 +
    1.54 +
    1.55 +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 "")^"]"
    1.56 + 
    1.57 +
    1.58 +fun proofs_to_string [] str = str
    1.59 +|   proofs_to_string (x::xs) str = let val newstr = proof_to_string x 
    1.60 +                                   in
    1.61 +                                       proofs_to_string xs (str^newstr)
    1.62 +                                   end
    1.63 +
    1.64 +
    1.65 +
    1.66 +fun init_proofstep_to_string (num, step, clause_strs) = (string_of_int num)^" "^(proofstep_to_string step)^" "^(clause_strs_to_string clause_strs "")^" "
    1.67 +
    1.68 +fun init_proofsteps_to_string [] str = str
    1.69 +|   init_proofsteps_to_string (x::xs) str = let val newstr = init_proofstep_to_string x 
    1.70 +                                   in
    1.71 +                                       init_proofsteps_to_string xs (str^newstr)
    1.72 +                                   end
    1.73 +  
    1.74 +
    1.75 +
    1.76 +(*** get a string representing the Isabelle ordered axioms ***)
    1.77 +
    1.78 +fun origAx_to_string (num,(meta,thmvars)) =let val clause_strs = get_meta_lits_bracket meta
    1.79 +                                         in
    1.80 +                                            (string_of_int num)^"OrigAxiom()"^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
    1.81 +                                         end
    1.82 +
    1.83 +
    1.84 +fun  origAxs_to_string [] str = str
    1.85 +|   origAxs_to_string (x::xs) str = let val newstr = origAx_to_string x 
    1.86 +                                   in
    1.87 +                                       origAxs_to_string xs (str^newstr)
    1.88 +                                   end
    1.89 +
    1.90 +
    1.91 +(*** get a string representing the Isabelle ordered axioms not used in the spass proof***)
    1.92 +
    1.93 +fun extraAx_to_string (num, (meta,thmvars)) = let val clause_strs = get_meta_lits_bracket meta
    1.94 +                                           in
    1.95 +                                              (string_of_int num)^"ExtraAxiom()"^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
    1.96 +                                           end
    1.97 +
    1.98 +
    1.99 +
   1.100 +fun  extraAxs_to_string [] str = str
   1.101 +|   extraAxs_to_string (x::xs) str = let val newstr = extraAx_to_string x 
   1.102 +                                   in
   1.103 +                                       extraAxs_to_string xs (str^newstr)
   1.104 +                                   end
   1.105 +
   1.106 +
   1.107 +
   1.108 +
   1.109 +
   1.110 +
   1.111 +fun is_axiom ( num:int,Axiom, str) = true
   1.112 +|   is_axiom (num, _,_) = false
   1.113 +
   1.114 +fun get_init_axioms xs = List.filter (is_axiom) ( xs)
   1.115 +
   1.116 +fun get_step_nums [] nums = nums
   1.117 +|   get_step_nums (( num:int,Axiom, str)::xs) nums = get_step_nums xs (nums@[num])
   1.118 +
   1.119 +fun assoc_snd a [] = raise Noassoc
   1.120 +  | assoc_snd a ((x, y)::t) = if a = y then x else assoc_snd a t;
   1.121 +
   1.122 +(* change to be something using check_order  instead of a = y --> returns true if ASSERTION not raised in checkorder, false otherwise *)
   1.123 +
   1.124 +(*fun get_assoc_snds [] xs assocs= assocs
   1.125 +|   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_snd x ys))])
   1.126 +*)
   1.127 +(*FIX - should this have vars in it? *)
   1.128 +fun there_out_of_order xs ys = let val foo = (checkorder xs ys [] ([],[],[])) 
   1.129 +                                   
   1.130 +                               in 
   1.131 +                                   true
   1.132 +                              end
   1.133 +                              handle EXCEP => false
   1.134 +
   1.135 +fun assoc_out_of_order a [] = raise Noassoc
   1.136 +|   assoc_out_of_order a ((b,c)::t) = if there_out_of_order a c then b else assoc_out_of_order a t;
   1.137 +
   1.138 +fun get_assoc_snds [] xs assocs= assocs
   1.139 +|   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_out_of_order x ys))])
   1.140 +
   1.141 +
   1.142 +
   1.143 +
   1.144 +fun add_if_not_inlist [] xs newlist = newlist
   1.145 +|   add_if_not_inlist (y::ys) xs newlist = if (not (inlist y xs)) then 
   1.146 +                                      add_if_not_inlist ys xs (y::newlist)
   1.147 +                                        else add_if_not_inlist ys xs (newlist)
   1.148 +
   1.149 +(*
   1.150 +fun is_alpha_space_neg_eq_colon ch = (ch = "~") orelse (is_alpha ch) orelse ( ch = " ")orelse  ( ch = ";") orelse( ch = "=")
   1.151 +
   1.152 +(* replace | by ; here *)
   1.153 +fun change_or [] = []
   1.154 +|   change_or (x::xs) = if x = "|" 
   1.155 +                          then 
   1.156 +                             [";"]@(change_or xs)
   1.157 +                          else (x::(change_or xs))
   1.158 +
   1.159 +
   1.160 +fun clause_lit_string t = let val termstr = (Sign.string_of_term Mainsign ) t
   1.161 +                              val exp_term = explode termstr
   1.162 +                              val colon_term = change_or exp_term
   1.163 +                   in
   1.164 +                             implode(List.filter is_alpha_space_neg_eq_colon colon_term)
   1.165 +                   end
   1.166 +
   1.167 +fun get_clause_lits thm =  clause_lit_string (prop_of thm)
   1.168 +*)
   1.169 +
   1.170 +
   1.171 +fun onestr [] str = str
   1.172 +|   onestr (x::xs) str = onestr xs (str^(concat x))
   1.173 +
   1.174 +fun thmstrings [] str = str
   1.175 +|   thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
   1.176 +
   1.177 +fun onelist [] newlist = newlist
   1.178 +|   onelist (x::xs) newlist = onelist xs (newlist@x)
   1.179 +
   1.180 +
   1.181 +(**** Code to support ordinary resolution, rather than Model Elimination ****)
   1.182 +
   1.183 +(*Convert a list of clauses (disjunctions) to meta-level clauses (==>), 
   1.184 +  with no contrapositives, for ordinary resolution.*)
   1.185 +
   1.186 +(*raises exception if no rules apply -- unlike RL*)
   1.187 +fun tryres (th, rl::rls) = (th RS rl handle THM _ => tryres(th,rls))
   1.188 +  | tryres (th, []) = raise THM("tryres", 0, [th]);
   1.189 +
   1.190 +val prop_of = #prop o rep_thm;
   1.191 +
   1.192 +
   1.193 +(*For ordinary resolution. *)
   1.194 +val resolution_clause_rules = [disj_assoc, make_neg_rule', make_pos_rule'];
   1.195 +(*Use "theorem naming" to label the clauses*)
   1.196 +fun name_thms label =
   1.197 +    let fun name1 (th, (k,ths)) =
   1.198 +	  (k-1, Thm.name_thm (label ^ string_of_int k, th) :: ths)
   1.199 +
   1.200 +    in  fn ths => #2 (foldr name1 (length ths, []) ths)  end;
   1.201 +
   1.202 +(*Find an all-negative support clause*)
   1.203 +fun is_negative th = forall (not o #1) (literals (prop_of th));
   1.204 +
   1.205 +val neg_clauses = List.filter is_negative;
   1.206 +
   1.207 +
   1.208 +
   1.209 +(*True if the given type contains bool anywhere*)
   1.210 +fun has_bool (Type("bool",_)) = true
   1.211 +  | has_bool (Type(_, Ts)) = exists has_bool Ts
   1.212 +  | has_bool _ = false;
   1.213 +  
   1.214 +
   1.215 +(*Create a meta-level Horn clause*)
   1.216 +fun make_horn crules th = make_horn crules (tryres(th,crules))
   1.217 +			  handle THM _ => th;
   1.218 +
   1.219 +
   1.220 +(*Raises an exception if any Vars in the theorem mention type bool. That would mean
   1.221 +  they are higher-order, and in addition, they could cause make_horn to loop!*)
   1.222 +fun check_no_bool th =
   1.223 +  if exists (has_bool o fastype_of) (term_vars (#prop (rep_thm th)))
   1.224 +  then raise THM ("check_no_bool", 0, [th]) else th;
   1.225 +
   1.226 +
   1.227 +(*Rules to convert the head literal into a negated assumption. If the head
   1.228 +  literal is already negated, then using notEfalse instead of notEfalse'
   1.229 +  prevents a double negation.*)
   1.230 +val notEfalse = read_instantiate [("R","False")] notE;
   1.231 +val notEfalse' = rotate_prems 1 notEfalse;
   1.232 +
   1.233 +fun negated_asm_of_head th = 
   1.234 +    th RS notEfalse handle THM _ => th RS notEfalse';
   1.235 +
   1.236 +(*Converting one clause*)
   1.237 +fun make_meta_clause th = 
   1.238 +	negated_asm_of_head (make_horn resolution_clause_rules (check_no_bool th));
   1.239 +
   1.240 +fun make_meta_clauses ths =
   1.241 +    name_thms "MClause#"
   1.242 +      (gen_distinct Drule.eq_thm_prop (map make_meta_clause ths));
   1.243 +
   1.244 +(*Permute a rule's premises to move the i-th premise to the last position.*)
   1.245 +fun make_last i th =
   1.246 +  let val n = nprems_of th 
   1.247 +  in  if 1 <= i andalso i <= n 
   1.248 +      then Thm.permute_prems (i-1) 1 th
   1.249 +      else raise THM("select_literal", i, [th])
   1.250 +  end;
   1.251 +
   1.252 +(*Maps a rule that ends "... ==> P ==> False" to "... ==> ~P" while suppressing
   1.253 +  double-negations.*)
   1.254 +val negate_head = rewrite_rule [atomize_not, not_not RS eq_reflection];
   1.255 +
   1.256 +(*Maps the clause  [P1,...Pn]==>False to [P1,...,P(i-1),P(i+1),...Pn] ==> ~P*)
   1.257 +fun select_literal i cl = negate_head (make_last i cl);
   1.258 +
   1.259 + fun get_axioms_used proof_steps thmstring = let 
   1.260 +                                             val  outfile = TextIO.openOut("foo_ax_thmstr");                                                                       
   1.261 +                                             val _ = TextIO.output (outfile, thmstring)
   1.262 +                                             
   1.263 +                                             val _ =  TextIO.closeOut outfile
   1.264 +                                            (* not sure why this is necessary again, but seems to be *)
   1.265 +                                            val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   1.266 +                                            val axioms = get_init_axioms proof_steps
   1.267 +                                            val step_nums = get_step_nums axioms []
   1.268 +                                            val thm = thm_of_string thmstring
   1.269 +                                            val clauses = make_clauses [thm]
   1.270 +                                            
   1.271 +                                            val vars = map thm_vars clauses
   1.272 +                                           
   1.273 +                                            val distvars = distinct (fold append vars [])
   1.274 +                                            val clause_terms = map prop_of clauses  
   1.275 +                                            val clause_frees = onelist (map term_frees clause_terms) []
   1.276 +
   1.277 +                                            val frees = map lit_string_with_nums clause_frees;
   1.278 +
   1.279 +                                            val distfrees = distinct frees
   1.280 +
   1.281 +                                            val metas = map make_meta_clause clauses
   1.282 +                                            val ax_strs = map (three_of_three ) axioms
   1.283 +
   1.284 +                                            (* literals of -all- axioms, not just those used by spass *)
   1.285 +                                            val meta_strs = map get_meta_lits metas
   1.286 +                                           
   1.287 +                                            val metas_and_strs = zip  metas meta_strs
   1.288 +                                             val  outfile = TextIO.openOut("foo_clauses");                                                                       
   1.289 +                                             val _ = TextIO.output (outfile, (onestr ax_strs ""))
   1.290 +                                             
   1.291 +                                             val _ =  TextIO.closeOut outfile
   1.292 +                                             val  outfile = TextIO.openOut("foo_metastrs");                                                                       
   1.293 +                                             val _ = TextIO.output (outfile, (onestr meta_strs ""))
   1.294 +                                             val _ =  TextIO.closeOut outfile
   1.295 +
   1.296 +                                            (* get list of axioms as thms with their variables *)
   1.297 +
   1.298 +                                            val ax_metas = get_assoc_snds ax_strs metas_and_strs []
   1.299 +                                            val ax_vars = map thm_vars ax_metas
   1.300 +                                            val ax_with_vars = zip ax_metas ax_vars
   1.301 +
   1.302 +                                            (* get list of extra axioms as thms with their variables *)
   1.303 +                                            val extra_metas = add_if_not_inlist metas ax_metas []
   1.304 +                                            val extra_vars = map thm_vars extra_metas
   1.305 +                                            val extra_with_vars = if (not (extra_metas = []) ) 
   1.306 +                                                                  then
   1.307 + 									 zip extra_metas extra_vars
   1.308 +                                                                  else
   1.309 +                                                                         []
   1.310 +
   1.311 +                                           (* val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
   1.312 +                                           val  outfile = TextIO.openOut("foo_metas")
   1.313 +
   1.314 +                                           val _ = TextIO.output (outfile, ((thmstrings ax_metas "")))
   1.315 +                                           val _ =  TextIO.closeOut outfile
   1.316 +                                            val execperl = Unix.execute("/usr/bin/perl", ["remchars2.pl <foo_metas >foo_metas2"])
   1.317 +                                         val infile = TextIO.openIn("foo_metas2")
   1.318 +                                        val ax_metas_str = TextIO.inputLine (infile)
   1.319 +                                        val _ = TextIO.closeIn infile
   1.320 +                                           val _= (print_mode := (["xsymbols", "symbols"] @ ! print_mode))*)
   1.321 +                                           
   1.322 +                                         in
   1.323 +                                            (distfrees,distvars, extra_with_vars,ax_with_vars, (zip step_nums ax_metas))
   1.324 +                                         end
   1.325 +                                        
   1.326 +fun thmstrings [] str = str
   1.327 +|   thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
   1.328 +
   1.329 +fun numclstr (vars, []) str = str
   1.330 +|   numclstr ( vars, ((num, thm)::rest)) str = let val newstr = str^(string_of_int num)^" "^(string_of_thm thm)^" "
   1.331 +                               in
   1.332 +                                   numclstr  (vars,rest) newstr
   1.333 +                               end
   1.334 +
   1.335 +(*
   1.336 +
   1.337 +val proofstr = "Did parsing on Here is a proof with depth 4, length 9 :\
   1.338 +\1[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*+ -> v_P(tconst_fun(typ__da_a,tconst_bool),U)*.\
   1.339 +\3[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),U)*+ -> v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*.\
   1.340 +\5[0:Inp] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),U)* v_P(tconst_fun(typ__da_a,tconst_bool),v_xa)*.\
   1.341 +\7[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),U)*+ v_P(tconst_fun(typ__da_a,tconst_bool),v_xb)* -> .\
   1.342 +\9[0:Fac:5.0,5.1] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),v_xa)*.\
   1.343 +\10[0:Res:9.0,3.0] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*.\
   1.344 +\11[0:Res:10.0,1.0] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),U)*.\
   1.345 +\12[0:Fac:7.0,7.1] || v_P(tconst_fun(typ__da_a,tconst_bool),v_xb)* -> .\
   1.346 +\14[0:Res:11.0,12.0] ||  -> .\
   1.347 +\Formulae used in the proof :"
   1.348 +
   1.349 +*)
   1.350 +
   1.351 +
   1.352 +fun addvars  c (a,b)  = (a,b,c)
   1.353 +
   1.354 +
   1.355 +
   1.356 +(*********************************************************************)
   1.357 +(* Pass in spass string of proof and string version of isabelle goal *)
   1.358 +(* Get out reconstruction steps as a string to be sent to Isabelle   *)
   1.359 +(*********************************************************************)
   1.360 +
   1.361 +
   1.362 +(*
   1.363 +
   1.364 +
   1.365 +val proofstr = "Here is a proof with depth 2, length 5 :\
   1.366 +\1[0:Inp] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
   1.367 +\3[0:Inp] || v_Q(tconst_fun(typ__asc39_a,tconst_bool),U)* -> .\
   1.368 +\5[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)* -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa).\
   1.369 +\7[0:Res:1.0,5.0] ||  -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
   1.370 +\9[0:Res:7.0,3.0] ||  -> .\
   1.371 +\Formulae used in the proof :"
   1.372 +
   1.373 +
   1.374 +val proofstr = "Here is a proof with depth 4, length 9 :\
   1.375 +\1[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*+ -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
   1.376 +\3[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*+ -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*.\
   1.377 +\5[0:Inp] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)* v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
   1.378 +\7[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*+ v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xb)* -> .\
   1.379 +\9[0:Fac:5.0,5.1] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
   1.380 +\10[0:Res:9.0,3.0] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*.\
   1.381 +\11[0:Res:10.0,1.0] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
   1.382 +\12[0:Fac:7.0,7.1] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xb)* -> .\
   1.383 +\14[0:Res:11.0,12.0] ||  -> .\
   1.384 +\Formulae used in the proof :";
   1.385 +
   1.386 +
   1.387 +val thmstring = " (~ (P::'a::type => bool) (x::'a::type) | P (U::'a::type)) & (~ (P::'a::type => bool) (U::'a::type) | P (x::'a::type)) & ((P::'a::type => bool) (xa::'a::type) | P (U::'a::type)) & (~ (P::'a::type => bool) (U::'a::type) | ~ P (xb::'a::type))";
   1.388 +
   1.389 +val thmstring = "(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)"
   1.390 +
   1.391 +
   1.392 +val thmstring ="(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)"
   1.393 +
   1.394 +val proofstr = "Did parsing on Here is a proof with depth 2, length 5 :\
   1.395 +\1[0:Inp] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
   1.396 +\3[0:Inp] || v_Q(tconst_fun(typ__asc39_a,tconst_bool),U)* -> .\
   1.397 +\5[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x(tconst_fun(typ__asc39_a,typ__asc39_a),U))* -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa(tconst_fun(typ__asc39_a,typ__asc39_a),U)).\
   1.398 +\7[0:Res:1.0,5.0] ||  -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa(tconst_fun(typ__asc39_a,typ__asc39_a),U))*.\
   1.399 +\9[0:Res:7.0,3.0] ||  -> .\
   1.400 +\Formulae used in the proof :";
   1.401 +
   1.402 +*)
   1.403 +
   1.404 +
   1.405 +fun spassString_to_reconString proofstr thmstring = 
   1.406 +                                              let val  outfile = TextIO.openOut("thmstringfile");                                                                                      val _= warning("proofstr is: "^proofstr);
   1.407 +                                                  val _ = warning ("thmstring is: "^thmstring);
   1.408 +                                                  val _ = TextIO.output (outfile, (thmstring))
   1.409 +                                                  val _ =  TextIO.closeOut outfile
   1.410 +                                                  val proofextract = extract_proof proofstr
   1.411 +                                                  val tokens = fst(lex proofextract)
   1.412 +                                                     
   1.413 +                                              (***********************************)
   1.414 +                                              (* parse spass proof into datatype *)
   1.415 +                                              (***********************************)
   1.416 +
   1.417 +                                                  val proof_steps1 = parse tokens
   1.418 +                                                  val proof_steps = just_change_space proof_steps1
   1.419 +
   1.420 +                                                  val  outfile = TextIO.openOut("foo_parse");                                                                                          val _ = TextIO.output (outfile, ("Did parsing on "^proofstr))
   1.421 +                                                  val _ =  TextIO.closeOut outfile
   1.422 +                                                
   1.423 +                                                  val  outfile = TextIO.openOut("foo_thmstring_at_parse");                                                                             val _ = TextIO.output (outfile, ("Parsing for thmstring: "^thmstring))
   1.424 +                                                  val _ =  TextIO.closeOut outfile
   1.425 +                                              (************************************)
   1.426 +                                              (* recreate original subgoal as thm *)
   1.427 +                                              (************************************)
   1.428 +                                                
   1.429 +                                                  (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
   1.430 +                                                  val (frees,vars,extra_with_vars ,ax_with_vars,numcls) = get_axioms_used proof_steps thmstring
   1.431 +                                                  
   1.432 +                                                  (*val numcls_string = numclstr ( vars, numcls) ""*)
   1.433 +                                                  val  outfile = TextIO.openOut("foo_axiom");                                                                            val _ = TextIO.output (outfile,"got axioms")
   1.434 +                                                  val _ =  TextIO.closeOut outfile
   1.435 +                                                    
   1.436 +                                              (************************************)
   1.437 +                                              (* translate proof                  *)
   1.438 +                                              (************************************)
   1.439 +                                                  val  outfile = TextIO.openOut("foo_steps");                                                          val _ = TextIO.output (outfile, ("about to translate proof, steps: "^(init_proofsteps_to_string proof_steps "")))
   1.440 +                                                  val _ =  TextIO.closeOut outfile
   1.441 +                                                  val (newthm,proof) = translate_proof numcls  proof_steps vars
   1.442 +                                                  val  outfile = TextIO.openOut("foo_steps2");                                                                         val _ = TextIO.output (outfile, ("translated proof, steps: "^(init_proofsteps_to_string proof_steps "")))
   1.443 +                                                  val _ =  TextIO.closeOut outfile
   1.444 +                                              (***************************************************)
   1.445 +                                              (* transfer necessary steps as strings to Isabelle *)
   1.446 +                                              (***************************************************)
   1.447 +                                                  (* turn the proof into a string *)
   1.448 +                                                  val reconProofStr = proofs_to_string proof ""
   1.449 +                                                  (* do the bit for the Isabelle ordered axioms at the top *)
   1.450 +                                                  val ax_nums = map fst numcls
   1.451 +                                                  val ax_strs = map get_meta_lits_bracket (map snd numcls)
   1.452 +                                                  val numcls_strs = zip ax_nums ax_strs
   1.453 +                                                  val num_cls_vars =  map (addvars vars) numcls_strs;
   1.454 +                                                  val reconIsaAxStr = origAxs_to_string (zip ax_nums ax_with_vars) ""
   1.455 +                                                  
   1.456 +                                                  val extra_nums = if (not (extra_with_vars = [])) then (1 upto (length extra_with_vars)) else []
   1.457 +                                                  val reconExtraAxStr = extraAxs_to_string ( zip extra_nums extra_with_vars) ""
   1.458 +                                                  val frees_str = "["^(thmvars_to_string frees "")^"]"
   1.459 +                                                  val  outfile = TextIO.openOut("reconstringfile");
   1.460 +
   1.461 +                                                  val _ = TextIO.output (outfile, (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr))
   1.462 +                                                  val _ =  TextIO.closeOut outfile
   1.463 +                                              in 
   1.464 +                                                   (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
   1.465 +                                              end
   1.466 +                                              handle _ => (let val  outfile = TextIO.openOut("foo_handler");
   1.467 +
   1.468 +                                                  val _ = TextIO.output (outfile, ("In exception handler"));
   1.469 +                                                  val _ =  TextIO.closeOut outfile
   1.470 +                                              in 
   1.471 +                                                 "Proof found but translation failed!"
   1.472 +                                              end)
   1.473 +
   1.474 +
   1.475 +
   1.476 +
   1.477 +
   1.478 +
   1.479 +
   1.480 +
   1.481 +
   1.482 +(**********************************************************************************)
   1.483 +(* At other end, want to turn back into datatype so can apply reconstruct_proof.  *)
   1.484 +(* This will be done by the signal handler                                        *)
   1.485 +(**********************************************************************************)
   1.486 +
   1.487 +(* Parse in the string version of the proof steps for reconstruction *)
   1.488 +(* Isar format: cl1 [BINARY 0 cl2 0];cl1 [PARAMOD 0 cl2 0]; cl1 [DEMOD 0 cl2];cl1 [FACTOR 1 2];*)
   1.489 +
   1.490 +
   1.491 + val term_numstep =
   1.492 +        (number ++ (a (Other ",")) ++ number) >> (fn (a, (_, c)) => (a, c))
   1.493 +
   1.494 +val extraaxiomstep = (a (Word "ExtraAxiom"))++ (a (Other "(")) ++(a (Other ")"))
   1.495 +            >> (fn (_) => ExtraAxiom)
   1.496 +
   1.497 +
   1.498 +
   1.499 +val origaxiomstep = (a (Word "OrigAxiom"))++ (a (Other "(")) ++(a (Other ")"))
   1.500 +            >> (fn (_) => OrigAxiom)
   1.501 +
   1.502 +
   1.503 + val axiomstep = (a (Word "Axiom"))++ (a (Other "(")) ++(a (Other ")"))
   1.504 +            >> (fn (_) => Axiom)
   1.505 +     
   1.506 +
   1.507 +
   1.508 +      
   1.509 + val binarystep = (a (Word "Binary")) ++ (a (Other "(")) ++ (a (Other "(")) 
   1.510 +                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   1.511 +                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   1.512 +            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Binary (c,e))
   1.513 +      
   1.514 +
   1.515 + val parastep = (a (Word "Para")) ++ (a (Other "(")) ++ (a (Other "(")) 
   1.516 +                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   1.517 +                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   1.518 +            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Para(c, e))
   1.519 +      
   1.520 + val mrrstep = (a (Word "MRR")) ++ (a (Other "(")) ++ (a (Other "(")) 
   1.521 +                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   1.522 +                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   1.523 +            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => MRR(c, e))
   1.524 +      
   1.525 +
   1.526 + val factorstep = (a (Word "Factor")) ++ (a (Other "("))
   1.527 +                    ++ number ++ (a (Other ","))
   1.528 +                       ++ number ++ (a (Other ","))
   1.529 +                       ++ number ++  (a (Other ")"))
   1.530 +                   
   1.531 +            >> (fn (_, (_, (c, (_, (e,(_,(f,_))))))) =>  Factor (c,e,f))
   1.532 +
   1.533 +
   1.534 +val rewritestep = (a (Word "Rewrite"))  ++ (a (Other "(")) ++ (a (Other "(")) 
   1.535 +                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
   1.536 +                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
   1.537 +            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Rewrite (c,e))
   1.538 +
   1.539 +val obviousstep = (a (Word "Obvious")) ++ (a (Other "(")) 
   1.540 +                   ++ term_numstep  ++ (a (Other ")")) 
   1.541 +            >> (fn (_, (_, (c,_))) => Obvious (c))
   1.542 +
   1.543 + val methodstep = extraaxiomstep || origaxiomstep || axiomstep ||binarystep || factorstep|| parastep || mrrstep || rewritestep || obviousstep
   1.544 +
   1.545 +
   1.546 + val number_list_step =
   1.547 +        ( number ++ many ((a (Other ",") ++ number)>> snd))
   1.548 +        >> (fn (a,b) => (a::b))
   1.549 +        
   1.550 + val numberlist_step = a (Other "[")  ++ a (Other "]")
   1.551 +                        >>(fn (_,_) => ([]:int list))
   1.552 +                       || a (Other "[") ++ number_list_step ++ a (Other "]")
   1.553 +                        >>(fn (_,(a,_)) => a)
   1.554 +                    
   1.555 +
   1.556 +
   1.557 +(** change this to allow P (x U) *)
   1.558 + fun arglist_step input = ( word ++ many  word >> (fn (a, b) => (a^" "^(implode_with_space b)))
   1.559 +                           ||word >> (fn (a) => (a)))input
   1.560 +                
   1.561 +
   1.562 +fun literal_step input = (word ++ a (Other "(") ++ arglist_step ++  a (Other ")")
   1.563 +                                          >>(fn (a, (b, (c,d))) => (a^" ("^(c)^")"))
   1.564 +                        || arglist_step >> (fn (a) => (a)))input
   1.565 +                           
   1.566 +
   1.567 +
   1.568 +(* fun term_step input = (a (Other "~") ++ arglist_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
   1.569 +                     ||  arglist_step ++ a (Other "%")>> (fn (a,b) => a ))input
   1.570 +*)
   1.571 +
   1.572 +
   1.573 + fun term_step input = (a (Other "~") ++ literal_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
   1.574 +                     ||  literal_step ++ a (Other "%")>> (fn (a,b) => a ))input
   1.575 +
   1.576 +
   1.577 +         
   1.578 +
   1.579 + val term_list_step =
   1.580 +        (  term_step ++ many ( term_step))
   1.581 +        >> (fn (a,b) => (a::b))
   1.582 +        
   1.583 + 
   1.584 +val term_lists_step = a (Other "[")  ++ a (Other "]")
   1.585 +                        >>(fn (_,_) => ([]:string list))
   1.586 +                       || a (Other "[") ++ term_list_step ++ a (Other "]")
   1.587 +                        >>(fn (_,(a,_)) => a)
   1.588 +                     
   1.589 +
   1.590 +
   1.591 +
   1.592 +fun anytoken_step input  = (word>> (fn (a) => a)  ) input
   1.593 +                       handle NOPARSE_WORD => (number>> (fn (a) => string_of_int a)  ) input
   1.594 +                      handle NOPARSE_NUMBER => (other_char >> (fn(a) => a)) input
   1.595 +
   1.596 +
   1.597 +
   1.598 +fun goalstring_step input= (anytoken_step ++ many (anytoken_step )
   1.599 +                  >> (fn (a,b) =>  (a^" "^(implode b)))) input
   1.600 +
   1.601 +
   1.602 +
   1.603 + val linestep = number ++ methodstep ++ term_lists_step ++ term_lists_step
   1.604 +                >> (fn (a, (b, (c,d))) => (a,(b,c,d)))
   1.605 +    
   1.606 + val lines_step = many linestep
   1.607 +
   1.608 + val alllines_step = (term_lists_step ++ lines_step ) ++ finished >> fst
   1.609 +    
   1.610 + val parse_step = fst o alllines_step
   1.611 +
   1.612 +
   1.613 + (*
   1.614 +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)"
   1.615 +*)
   1.616 +
   1.617 +(************************************************************)
   1.618 +(* Construct an Isar style proof from a list of proof steps *)
   1.619 +(************************************************************)
   1.620 +(* want to assume all axioms, then do haves for the other clauses*)
   1.621 +(* then show for the last step *)
   1.622 +fun one_of_three (a,b,c) = a;
   1.623 +fun two_of_three (a,b,c) = b;
   1.624 +fun three_of_three (a,b,c) = c;
   1.625 +
   1.626 +(* replace ~ by not here *)
   1.627 +fun change_nots [] = []
   1.628 +|   change_nots (x::xs) = if x = "~" 
   1.629 +                          then 
   1.630 +                             ["\\", "<", "n", "o", "t", ">"]@(change_nots xs)
   1.631 +                          else (x::(change_nots xs))
   1.632 +
   1.633 +(*
   1.634 +fun clstrs_to_string [] str = str
   1.635 +|   clstrs_to_string (x::[]) str = str^x
   1.636 +|   clstrs_to_string (x::xs) str = clstrs_to_string xs (str^(x^"; "))
   1.637 +*)
   1.638 +fun clstrs_to_string [] str = implode (change_nots (explode str))
   1.639 +|   clstrs_to_string (x::[]) str = implode (change_nots (explode (str^x)))
   1.640 +|   clstrs_to_string (x::xs) str = implode (change_nots (explode (clstrs_to_string xs (str^(x^"; ")))))
   1.641 +
   1.642 +
   1.643 +
   1.644 +fun thmvars_to_quantstring [] str = str
   1.645 +|   thmvars_to_quantstring (x::[]) str =str^x^". "
   1.646 +|   thmvars_to_quantstring (x::xs) str = thmvars_to_quantstring xs (str^(x^" "))
   1.647 +
   1.648 +
   1.649 +fun clause_strs_to_isar clstrs [] =  "\"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> "^" \\<Longrightarrow> False\""
   1.650 +|   clause_strs_to_isar clstrs thmvars = "\"\\<And>"^(thmvars_to_quantstring thmvars "")^"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> "^"\\<Longrightarrow> False\""
   1.651 +
   1.652 +fun frees_to_string [] str = implode (change_nots (explode str))
   1.653 +|   frees_to_string (x::[]) str = implode (change_nots (explode (str^x)))
   1.654 +|   frees_to_string  (x::xs) str = implode (change_nots (explode (frees_to_string xs (str^(x^" ")))))
   1.655 +
   1.656 +fun frees_to_isar_str [] =  ""
   1.657 +|   frees_to_isar_str  clstrs = (frees_to_string clstrs "")
   1.658 +
   1.659 +
   1.660 +(***********************************************************************)
   1.661 +(* functions for producing assumptions for the Isabelle ordered axioms *)
   1.662 +(***********************************************************************)
   1.663 +(*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))[][]";       
   1.664 +num, rule, clausestrs, vars*)
   1.665 +
   1.666 +
   1.667 +(* assume the extra clauses - not used in Spass proof *)
   1.668 +
   1.669 +fun is_extraaxiom_step ( num:int,(ExtraAxiom, str, tstr)) = true
   1.670 +|   is_extraaxiom_step (num, _) = false
   1.671 +
   1.672 +fun get_extraaxioms xs = List.filter (is_extraaxiom_step) ( xs)
   1.673 +
   1.674 +fun assume_isar_extraaxiom [] str  = str
   1.675 +|   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 " )
   1.676 +
   1.677 +
   1.678 +
   1.679 +fun assume_isar_extraaxioms  [] = ""
   1.680 +|assume_isar_extraaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n" 
   1.681 +                                         in
   1.682 +                                             assume_isar_extraaxiom xs str
   1.683 +                                         end
   1.684 +
   1.685 +(* assume the Isabelle ordered clauses *)
   1.686 +
   1.687 +fun is_origaxiom_step ( num:int,(OrigAxiom, str, tstr)) = true
   1.688 +|   is_origaxiom_step (num, _) = false
   1.689 +
   1.690 +fun get_origaxioms xs = List.filter (is_origaxiom_step) ( xs)
   1.691 +
   1.692 +fun assume_isar_origaxiom [] str  = str
   1.693 +|   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 " )
   1.694 +
   1.695 +
   1.696 +
   1.697 +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" 
   1.698 +                                         in
   1.699 +                                             assume_isar_origaxiom xs str
   1.700 +                                         end
   1.701 +
   1.702 +
   1.703 +
   1.704 +fun is_axiom_step ( num:int,(Axiom, str, tstr)) = true
   1.705 +|   is_axiom_step (num, _) = false
   1.706 +
   1.707 +fun get_axioms xs = List.filter  (is_axiom_step) ( xs)
   1.708 +
   1.709 +fun have_isar_axiomline (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
   1.710 +
   1.711 +fun  by_isar_axiomline (numb,(step, clstrs, thmstrs))="by (rule cl"^ (string_of_int numb)^"') \n"
   1.712 +
   1.713 +
   1.714 +fun isar_axiomline (numb, (step, clstrs, thmstrs))  = (have_isar_axiomline (numb,(step,clstrs, thmstrs )))^( by_isar_axiomline(numb,(step,clstrs, thmstrs )) )
   1.715 +
   1.716 +
   1.717 +fun isar_axiomlines [] str = str
   1.718 +|   isar_axiomlines (x::xs) str = isar_axiomlines xs (str^(isar_axiomline x))
   1.719 +
   1.720 +
   1.721 +fun have_isar_line (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
   1.722 +
   1.723 +
   1.724 +fun  by_isar_line ((Binary ((a,b), (c,d))))="by(rule cl"^
   1.725 +                                                  (string_of_int a)^" [BINARY "^(string_of_int b)^" "^"cl"^
   1.726 +                                                  (string_of_int c)^" "^(string_of_int d)^"])"^"\n"
   1.727 +|   by_isar_line ( (Para ((a,b), (c,d)))) ="by (rule cl"^
   1.728 +                                                  (string_of_int a)^" [PARAMOD "^(string_of_int b)^" "^"cl"^
   1.729 +                                                  (string_of_int c)^" "^(string_of_int d)^"])"^"\n"
   1.730 +|   by_isar_line ((Factor ((a,b,c)))) =    "by (rule cl"^(string_of_int a)^" [FACTOR "^(string_of_int b)^" "^
   1.731 +                                                  (string_of_int c)^" "^"])"^"\n"
   1.732 +|   by_isar_line ( (Rewrite ((a,b),(c,d)))) =  "by (rule cl"^(string_of_int a)^" [DEMOD "^(string_of_int b)^" "^
   1.733 +                                                  (string_of_int c)^" "^(string_of_int d)^" "^"])"^"\n"
   1.734 +
   1.735 +|   by_isar_line ( (Obvious ((a,b)))) =  "by (rule cl"^(string_of_int a)^" [OBVIOUS "^(string_of_int b)^" ])"^"\n"
   1.736 +
   1.737 +fun isar_line (numb, (step, clstrs, thmstrs))  = (have_isar_line (numb,(step,clstrs, thmstrs )))^( by_isar_line step)
   1.738 +
   1.739 +
   1.740 +fun isar_lines [] str = str
   1.741 +|   isar_lines (x::xs) str = isar_lines xs (str^(isar_line x))
   1.742 +
   1.743 +fun last_isar_line (numb,( step, clstrs,thmstrs)) = "show \"False\"\n"^(by_isar_line step)
   1.744 +
   1.745 +
   1.746 +fun to_isar_proof (frees, xs, goalstring) = let val extraaxioms = get_extraaxioms xs
   1.747 +                           val extraax_num = length extraaxioms
   1.748 +                           val origaxioms_and_steps = drop (extraax_num) xs  
   1.749 +                          
   1.750 +  
   1.751 +                           val origaxioms = get_origaxioms origaxioms_and_steps
   1.752 +                           val origax_num = length origaxioms
   1.753 +                           val axioms_and_steps = drop (origax_num + extraax_num) xs  
   1.754 +                           val axioms = get_axioms axioms_and_steps
   1.755 +                           
   1.756 +                           val steps = drop origax_num axioms_and_steps
   1.757 +                           val firststeps = butlast steps
   1.758 +                           val laststep = last steps
   1.759 +                           val goalstring = implode(butlast(explode goalstring))
   1.760 +                        
   1.761 +                           val isar_proof = 
   1.762 +                           ("show \""^goalstring^"\"\n")^
   1.763 +                           ("proof (rule ccontr,skolemize, make_clauses) \n")^
   1.764 +                           ("fix "^(frees_to_isar_str frees)^"\n")^
   1.765 +                           (assume_isar_extraaxioms extraaxioms)^
   1.766 +                           (assume_isar_origaxioms origaxioms)^
   1.767 +                           (isar_axiomlines axioms "")^
   1.768 +                           (isar_lines firststeps "")^
   1.769 +                           (last_isar_line laststep)^
   1.770 +                           ("qed")
   1.771 +                          val  outfile = TextIO.openOut("isar_proof_file");
   1.772 +
   1.773 +                                                  val _ = TextIO.output (outfile, isar_proof)
   1.774 +                                                  val _ =  TextIO.closeOut outfile
   1.775 +
   1.776 +
   1.777 +                       in
   1.778 +                           isar_proof
   1.779 +                       end
   1.780 +
   1.781 +(* get fix vars from axioms - all Frees *)
   1.782 +(* check each clause for meta-vars and /\ over them at each step*)
   1.783 +
   1.784 +(*******************************************************)
   1.785 +(* This assumes the thm list  "numcls" is still there  *)
   1.786 +(* In reality, should probably label it with an        *)
   1.787 +(* ID number identifying the subgoal.  This could      *)
   1.788 +(* be passed over to the watcher, e.g.  numcls25       *)
   1.789 +(*******************************************************)
   1.790 +
   1.791 +(* 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))[][]";
   1.792 +
   1.793 +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))[][]";
   1.794 +
   1.795 +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)";
   1.796 +
   1.797 +
   1.798 +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))[][]";
   1.799 +
   1.800 +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)))";
   1.801 +*)
   1.802 +
   1.803 +fun apply_res_thm str goalstring  = let val tokens = fst (lex str);
   1.804 +
   1.805 +                                   val (frees,recon_steps) = parse_step tokens 
   1.806 +                                   val isar_str = to_isar_proof (frees, recon_steps, goalstring)
   1.807 +                                   val foo =   TextIO.openOut "foobar";
   1.808 +                               in 
   1.809 +                                  TextIO.output(foo,(isar_str));TextIO.closeOut foo;Pretty.writeln(Pretty.str  isar_str); () 
   1.810 +                               end 
   1.811 +
   1.812 +