src/HOL/Tools/ATP/recon_transfer_proof.ML
author paulson
Fri Sep 09 17:47:37 2005 +0200 (2005-09-09)
changeset 17317 3f12de2e2e6e
parent 17315 5bf0e0aacc24
child 17422 3b237822985d
permissions -rw-r--r--
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson@15789
     1
(*  ID:         $Id$
wenzelm@16259
     2
    Author:     Claire Quigley
wenzelm@16259
     3
    Copyright   2004  University of Cambridge
paulson@15789
     4
*)
paulson@15789
     5
paulson@15684
     6
structure Recon_Transfer =
paulson@15684
     7
struct
wenzelm@16803
     8
paulson@15684
     9
open Recon_Parse
wenzelm@16803
    10
paulson@15684
    11
infixr 8 ++; infixr 7 >>; infixr 6 ||;
paulson@15684
    12
quigley@15642
    13
quigley@15642
    14
(* Versions that include type information *)
quigley@15642
    15
 
wenzelm@16803
    16
(* FIXME rename to str_of_thm *)
paulson@16157
    17
fun string_of_thm thm =
wenzelm@16803
    18
  setmp show_sorts true (Pretty.str_of o Display.pretty_thm) thm;
quigley@15642
    19
quigley@15642
    20
quigley@15642
    21
(* check separate args in the watcher program for separating strings with a * or ; or something *)
quigley@15642
    22
quigley@15642
    23
fun clause_strs_to_string [] str = str
quigley@15642
    24
|   clause_strs_to_string (x::xs) str = clause_strs_to_string xs (str^x^"%")
quigley@15642
    25
quigley@15642
    26
fun thmvars_to_string [] str = str
quigley@15642
    27
|   thmvars_to_string (x::xs) str = thmvars_to_string xs (str^x^"%")
quigley@15642
    28
quigley@15642
    29
quigley@15642
    30
fun proofstep_to_string Axiom = "Axiom()"
paulson@16091
    31
|   proofstep_to_string  (Binary ((a,b), (c,d)))=
paulson@16091
    32
      "Binary(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"
paulson@16091
    33
|   proofstep_to_string (Factor (a,b,c)) =
paulson@16091
    34
      "Factor("^(string_of_int a)^","^(string_of_int b)^","^(string_of_int c)^")"
paulson@16091
    35
|   proofstep_to_string  (Para ((a,b), (c,d)))= 
paulson@16091
    36
      "Para(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"
paulson@16091
    37
|   proofstep_to_string  (MRR ((a,b), (c,d))) =
paulson@16091
    38
      "MRR(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"
quigley@16548
    39
(*|   proofstep_to_string (Rewrite((a,b),(c,d))) =
quigley@16548
    40
      "Rewrite(("^(string_of_int a)^","^(string_of_int b)^"),("^(string_of_int c)^","^(string_of_int d)^"))"*)
quigley@15642
    41
quigley@15642
    42
fun list_to_string [] liststr = liststr
quigley@15642
    43
|   list_to_string (x::[]) liststr = liststr^(string_of_int x)
quigley@15642
    44
|   list_to_string (x::xs) liststr = list_to_string xs (liststr^(string_of_int x)^",")
quigley@15642
    45
quigley@15642
    46
paulson@16091
    47
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 "")^"]"
quigley@15642
    48
 
quigley@15642
    49
quigley@15642
    50
fun proofs_to_string [] str = str
quigley@15642
    51
|   proofs_to_string (x::xs) str = let val newstr = proof_to_string x 
quigley@15642
    52
                                   in
quigley@15642
    53
                                       proofs_to_string xs (str^newstr)
quigley@15642
    54
                                   end
quigley@15642
    55
quigley@15642
    56
quigley@15642
    57
quigley@15642
    58
fun init_proofstep_to_string (num, step, clause_strs) = (string_of_int num)^" "^(proofstep_to_string step)^" "^(clause_strs_to_string clause_strs "")^" "
quigley@15642
    59
quigley@15642
    60
fun init_proofsteps_to_string [] str = str
quigley@15642
    61
|   init_proofsteps_to_string (x::xs) str = let val newstr = init_proofstep_to_string x 
quigley@15642
    62
                                   in
quigley@15642
    63
                                       init_proofsteps_to_string xs (str^newstr)
quigley@15642
    64
                                   end
quigley@15642
    65
  
quigley@15642
    66
quigley@15642
    67
quigley@15642
    68
(*** get a string representing the Isabelle ordered axioms ***)
quigley@15642
    69
paulson@16061
    70
fun origAx_to_string (num,(meta,thmvars)) =
paulson@16061
    71
    let val clause_strs = ReconOrderClauses.get_meta_lits_bracket meta
paulson@16061
    72
    in
paulson@16091
    73
       (string_of_int num)^"OrigAxiom()["^
paulson@16091
    74
       (clause_strs_to_string clause_strs "")^"]["^
paulson@16061
    75
       (thmvars_to_string thmvars "")^"]"
paulson@16061
    76
    end
quigley@15642
    77
quigley@15642
    78
quigley@15642
    79
fun  origAxs_to_string [] str = str
quigley@15642
    80
|   origAxs_to_string (x::xs) str = let val newstr = origAx_to_string x 
quigley@15642
    81
                                   in
quigley@15642
    82
                                       origAxs_to_string xs (str^newstr)
quigley@15642
    83
                                   end
quigley@15642
    84
quigley@15642
    85
quigley@15642
    86
(*** get a string representing the Isabelle ordered axioms not used in the spass proof***)
quigley@15642
    87
paulson@16061
    88
fun extraAx_to_string (num, (meta,thmvars)) =
paulson@16061
    89
   let val clause_strs = ReconOrderClauses.get_meta_lits_bracket meta
paulson@16061
    90
   in
paulson@16091
    91
      (string_of_int num)^"ExtraAxiom()["^
paulson@16061
    92
      (clause_strs_to_string clause_strs "")^"]"^
paulson@16061
    93
      "["^(thmvars_to_string thmvars "")^"]"
paulson@16061
    94
   end;
quigley@15642
    95
paulson@16061
    96
fun extraAxs_to_string [] str = str
paulson@16061
    97
|   extraAxs_to_string (x::xs) str =
paulson@16061
    98
      let val newstr = extraAx_to_string x 
paulson@16061
    99
      in
paulson@16061
   100
	  extraAxs_to_string xs (str^newstr)
paulson@16061
   101
      end;
quigley@15642
   102
paulson@17312
   103
fun is_axiom (_,Axiom,str) = true
paulson@17312
   104
|   is_axiom (_,_,_) = false
quigley@15642
   105
quigley@15642
   106
fun get_step_nums [] nums = nums
quigley@15642
   107
|   get_step_nums (( num:int,Axiom, str)::xs) nums = get_step_nums xs (nums@[num])
quigley@15642
   108
paulson@15774
   109
exception Noassoc;
paulson@15774
   110
paulson@15774
   111
fun assoc_snd a [] = raise Noassoc
quigley@15642
   112
  | assoc_snd a ((x, y)::t) = if a = y then x else assoc_snd a t;
quigley@15642
   113
quigley@15642
   114
(* change to be something using check_order  instead of a = y --> returns true if ASSERTION not raised in checkorder, false otherwise *)
quigley@15642
   115
quigley@15642
   116
(*fun get_assoc_snds [] xs assocs= assocs
quigley@15642
   117
|   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_snd x ys))])
quigley@15642
   118
*)
quigley@15642
   119
(*FIX - should this have vars in it? *)
paulson@16061
   120
fun there_out_of_order xs ys = (ReconOrderClauses.checkorder xs ys [] ([],[],[]); true) 
paulson@15774
   121
                               handle _ => false
quigley@15642
   122
paulson@15774
   123
fun assoc_out_of_order a [] = raise Noassoc
quigley@15642
   124
|   assoc_out_of_order a ((b,c)::t) = if there_out_of_order a c then b else assoc_out_of_order a t;
quigley@15642
   125
quigley@15642
   126
fun get_assoc_snds [] xs assocs= assocs
quigley@15642
   127
|   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_out_of_order x ys))])
quigley@15642
   128
quigley@15642
   129
fun add_if_not_inlist [] xs newlist = newlist
paulson@16157
   130
|   add_if_not_inlist (y::ys) xs newlist = if (not (y mem xs)) then 
quigley@15642
   131
                                      add_if_not_inlist ys xs (y::newlist)
quigley@15642
   132
                                        else add_if_not_inlist ys xs (newlist)
quigley@15642
   133
paulson@15700
   134
(*Flattens a list of list of strings to one string*)
paulson@15700
   135
fun onestr ls = String.concat (map String.concat ls);
quigley@15642
   136
quigley@15642
   137
fun thmstrings [] str = str
quigley@15642
   138
|   thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
quigley@15642
   139
paulson@17315
   140
fun is_clasimp_ax clasimp_num n = n <= clasimp_num 
quigley@15919
   141
quigley@16156
   142
fun subone x = x - 1
quigley@16156
   143
quigley@16156
   144
fun numstr [] = ""
quigley@16156
   145
|   numstr (x::xs) = (string_of_int x)^"%"^(numstr xs)
quigley@16156
   146
quigley@15919
   147
quigley@15919
   148
(* retrieve the axioms that were obtained from the clasimpset *)
quigley@15919
   149
paulson@17312
   150
fun get_clasimp_cls (clause_arr: (ResClause.clause * thm) array) clasimp_num step_nums = 
paulson@16157
   151
    let val realnums = map subone step_nums	
paulson@16157
   152
	val clasimp_nums = List.filter (is_clasimp_ax (clasimp_num - 1)) realnums
quigley@16478
   153
(*	val axnums = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "axnums")))     
paulson@16157
   154
	val _ = TextIO.output(axnums,(numstr clasimp_nums))
quigley@16478
   155
	val _ = TextIO.closeOut(axnums)*)
paulson@16157
   156
    in
paulson@17315
   157
	map (fn x =>  Array.sub(clause_arr, x)) clasimp_nums
paulson@16157
   158
    end
quigley@15919
   159
quigley@16156
   160
quigley@16357
   161
(*****************************************************)
quigley@16357
   162
(* get names of clasimp axioms used                  *)
quigley@16357
   163
(*****************************************************)
quigley@16156
   164
paulson@17312
   165
 fun get_axiom_names step_nums thms clause_arr num_of_clauses =
paulson@16157
   166
   let 
paulson@16157
   167
     (* not sure why this is necessary again, but seems to be *)
paulson@16157
   168
      val _ = (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
paulson@16157
   169
  
paulson@16157
   170
     (***********************************************)
paulson@16157
   171
     (* here need to add the clauses from clause_arr*)
paulson@16157
   172
     (***********************************************)
paulson@16157
   173
  
paulson@17312
   174
      val clasimp_names_cls = get_clasimp_cls clause_arr num_of_clauses step_nums 
paulson@17317
   175
      val clasimp_names = map (ResClause.get_axiomName o #1) clasimp_names_cls
paulson@16157
   176
      val _ = File.write (File.tmp_path (Path.basic "clasimp_names"))                                                               
paulson@16157
   177
                         (concat clasimp_names)
paulson@16157
   178
      val _ = (print_mode := (["xsymbols", "symbols"] @ ! print_mode))
paulson@16157
   179
   in
paulson@16157
   180
      clasimp_names
paulson@16157
   181
   end
paulson@17306
   182
   
paulson@17315
   183
paulson@17315
   184
fun get_axiom_names_spass proofstr thms clause_arr num_of_clauses =
paulson@17315
   185
  let (* parse spass proof into datatype *)
paulson@17315
   186
      val tokens = #1(lex proofstr)
paulson@17315
   187
      val proof_steps = parse tokens
paulson@17315
   188
      val _ = File.write (File.tmp_path (Path.basic "parsing_done")) 
paulson@17315
   189
                         ("Did parsing on "^proofstr)
paulson@17315
   190
      (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
paulson@17315
   191
  in
paulson@17315
   192
    get_axiom_names (get_step_nums (List.filter is_axiom proof_steps) []) 
paulson@17315
   193
                    thms clause_arr num_of_clauses
paulson@17315
   194
  end;
quigley@16357
   195
    
paulson@17306
   196
 fun get_axiom_names_vamp_E proofstr thms clause_arr num_of_clauses  =
paulson@17306
   197
   get_axiom_names (get_linenums proofstr) thms clause_arr num_of_clauses;
paulson@17306
   198
    
quigley@17235
   199
quigley@16357
   200
(***********************************************)
quigley@16357
   201
(* get axioms for reconstruction               *)
quigley@16357
   202
(***********************************************)
quigley@16156
   203
fun numclstr (vars, []) str = str
paulson@16157
   204
|   numclstr ( vars, ((num, thm)::rest)) str =
paulson@16157
   205
      let val newstr = str^(string_of_int num)^" "^(string_of_thm thm)^" "
paulson@16157
   206
      in
paulson@16157
   207
        numclstr  (vars,rest) newstr
paulson@16157
   208
      end
quigley@15919
   209
paulson@16157
   210
fun addvars c (a,b)  = (a,b,c)
quigley@15919
   211
paulson@17315
   212
fun get_axioms_used proof_steps thms clause_arr num_of_clauses  =
paulson@17315
   213
  let 
paulson@17315
   214
     val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
paulson@17315
   215
     val axioms = (List.filter is_axiom) proof_steps
paulson@17315
   216
     val step_nums = get_step_nums axioms []
quigley@15919
   217
paulson@17315
   218
     val clauses =(*(clasimp_cls)@*)( make_clauses thms)
paulson@17315
   219
     
paulson@17315
   220
     val vars = map thm_vars clauses
paulson@17315
   221
    
paulson@17315
   222
     val distvars = distinct (fold append vars [])
paulson@17315
   223
     val clause_terms = map prop_of clauses  
paulson@17315
   224
     val clause_frees = List.concat (map term_frees clause_terms)
quigley@15642
   225
paulson@17315
   226
     val frees = map lit_string_with_nums clause_frees;
quigley@15642
   227
paulson@17315
   228
     val distfrees = distinct frees
quigley@15642
   229
paulson@17315
   230
     val metas = map Meson.make_meta_clause clauses
paulson@17315
   231
     val ax_strs = map #3 axioms
quigley@15642
   232
paulson@17315
   233
     (* literals of -all- axioms, not just those used by spass *)
paulson@17315
   234
     val meta_strs = map ReconOrderClauses.get_meta_lits metas
paulson@17315
   235
    
paulson@17315
   236
     val metas_and_strs = ListPair.zip (metas,meta_strs)
paulson@17315
   237
     val _ = File.write(File.tmp_path (Path.basic "foo_clauses")) (onestr ax_strs)
paulson@17315
   238
     val _ = File.write(File.tmp_path (Path.basic "foo_metastrs")) (onestr meta_strs)
quigley@15642
   239
paulson@17315
   240
     (* get list of axioms as thms with their variables *)
quigley@15642
   241
paulson@17315
   242
     val ax_metas = get_assoc_snds ax_strs metas_and_strs []
paulson@17315
   243
     val ax_vars = map thm_vars ax_metas
paulson@17315
   244
     val ax_with_vars = ListPair.zip (ax_metas,ax_vars)
quigley@15642
   245
paulson@17315
   246
     (* get list of extra axioms as thms with their variables *)
paulson@17315
   247
     val extra_metas = add_if_not_inlist metas ax_metas []
paulson@17315
   248
     val extra_vars = map thm_vars extra_metas
paulson@17315
   249
     val extra_with_vars = if (not (extra_metas = []) ) 
paulson@17315
   250
			   then ListPair.zip (extra_metas,extra_vars)
paulson@17315
   251
			   else []
paulson@17315
   252
  in
paulson@17315
   253
     (distfrees,distvars, extra_with_vars,ax_with_vars, ListPair.zip (step_nums,ax_metas))
paulson@17315
   254
  end;
paulson@16905
   255
                                            
quigley@15642
   256
quigley@15642
   257
(*********************************************************************)
quigley@15642
   258
(* Pass in spass string of proof and string version of isabelle goal *)
quigley@15642
   259
(* Get out reconstruction steps as a string to be sent to Isabelle   *)
quigley@15642
   260
(*********************************************************************)
quigley@15642
   261
paulson@17122
   262
fun rules_to_string [] = "NONE"
paulson@17122
   263
  | rules_to_string xs = "[" ^ space_implode ", " xs ^ "]"
quigley@16357
   264
paulson@16905
   265
fun subst_for a b = String.translate (fn c => str (if c=a then b else c));
quigley@16357
   266
paulson@16905
   267
val remove_linebreaks = subst_for #"\n" #"\t";
paulson@16905
   268
val restore_linebreaks = subst_for #"\t" #"\n";
quigley@16357
   269
quigley@16478
   270
paulson@17315
   271
fun proverString_to_lemmaString_aux proofstr thmstring goalstring toParent ppid thms clause_arr num_of_clauses getax = 
paulson@16905
   272
 let val _ = File.append(File.tmp_path (Path.basic "thmstringfile"))
paulson@17315
   273
               ("thmstring is " ^ thmstring ^ 
paulson@17315
   274
                "\nproofstr is " ^ proofstr ^
paulson@17315
   275
                "\ngoalstr is " ^ goalstring ^
paulson@17315
   276
                "\nnum of clauses is " ^ string_of_int num_of_clauses)
quigley@16478
   277
paulson@17315
   278
     val axiom_names = getax proofstr thms clause_arr num_of_clauses
paulson@17315
   279
     val ax_str = "Rules from clasimpset used in automatic proof: " ^
quigley@17235
   280
                  rules_to_string axiom_names
quigley@17235
   281
    in 
paulson@17312
   282
	 File.append(File.tmp_path (Path.basic "reconstrfile"))
paulson@17312
   283
	            ("reconstring is: "^ax_str^"  "^goalstring);
quigley@17235
   284
         TextIO.output (toParent, ax_str^"\n");
paulson@17312
   285
	 TextIO.output (toParent, "goalstring: "^goalstring^"\n");
quigley@17235
   286
	 TextIO.output (toParent, "thmstring: "^thmstring^"\n");
quigley@17235
   287
	 TextIO.flushOut toParent;
quigley@17235
   288
quigley@17235
   289
	 Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
quigley@17235
   290
	(* Attempt to prevent several signals from turning up simultaneously *)
paulson@17306
   291
	 Posix.Process.sleep(Time.fromSeconds 1) ; all_tac
quigley@17235
   292
    end
paulson@17315
   293
    handle _ => (*FIXME: exn handler is too general!*)
paulson@17315
   294
     (File.write(File.tmp_path (Path.basic "proverString_handler")) "In exception handler";
paulson@17315
   295
      TextIO.output (toParent, "Proof found but translation failed : " ^ 
paulson@17315
   296
                     remove_linebreaks proofstr ^ "\n");
paulson@17315
   297
      TextIO.output (toParent, remove_linebreaks thmstring ^ "\n");
paulson@17315
   298
      TextIO.output (toParent, remove_linebreaks goalstring ^ "\n");
paulson@17315
   299
      TextIO.flushOut toParent;
paulson@17315
   300
      Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
paulson@17315
   301
      (* Attempt to prevent several signals from turning up simultaneously *)
paulson@17315
   302
      Posix.Process.sleep(Time.fromSeconds 1); all_tac);
quigley@17235
   303
paulson@17315
   304
fun proverString_to_lemmaString proofstr thmstring goalstring toParent ppid thms
paulson@17315
   305
      clause_arr num_of_clauses  = 
paulson@17315
   306
  proverString_to_lemmaString_aux proofstr thmstring goalstring toParent ppid thms        
paulson@17315
   307
       clause_arr num_of_clauses get_axiom_names_vamp_E;
paulson@17315
   308
paulson@17315
   309
fun spassString_to_lemmaString proofstr thmstring goalstring toParent ppid thms
paulson@17315
   310
      clause_arr  num_of_clauses  = 
paulson@17315
   311
  proverString_to_lemmaString_aux proofstr thmstring goalstring toParent ppid thms        
paulson@17315
   312
       clause_arr num_of_clauses get_axiom_names_spass;
paulson@17315
   313
paulson@17315
   314
paulson@17315
   315
(**** Full proof reconstruction for SPASS (not really working) ****)
quigley@15642
   316
quigley@15919
   317
fun spassString_to_reconString proofstr thmstring goalstring toParent ppid thms clause_arr  num_of_clauses  = 
paulson@16905
   318
  let val _ = File.write(File.tmp_path (Path.basic "thmstringfile")) 
paulson@16905
   319
                 (" thmstring is: "^thmstring^"proofstr is: "^proofstr)
paulson@16905
   320
      val tokens = #1(lex proofstr)
quigley@15782
   321
paulson@16905
   322
  (***********************************)
paulson@16905
   323
  (* parse spass proof into datatype *)
paulson@16905
   324
  (***********************************)
paulson@17306
   325
      val proof_steps = parse tokens
quigley@15919
   326
paulson@16905
   327
      val _ = File.write (File.tmp_path (Path.basic "foo_parse"))
paulson@16905
   328
                      ("Did parsing on "^proofstr)
paulson@16905
   329
    
paulson@16905
   330
      val _ = File.write (File.tmp_path (Path.basic "foo_thmstring_at_parse"))
paulson@16905
   331
                                ("Parsing for thmstring: "^thmstring)
paulson@16905
   332
  (************************************)
paulson@16905
   333
  (* recreate original subgoal as thm *)
paulson@16905
   334
  (************************************)
paulson@16905
   335
      (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
paulson@16905
   336
      (* need to get prems_of thm, then get right one of the prems, relating to whichever*)
paulson@16905
   337
      (* subgoal this is, and turn it into meta_clauses *)
paulson@16905
   338
      (* should prob add array and table here, so that we can get axioms*)
paulson@16905
   339
      (* produced from the clasimpset rather than the problem *)
paulson@16905
   340
      val (frees,vars,extra_with_vars ,ax_with_vars,numcls) = get_axioms_used proof_steps  thms clause_arr  num_of_clauses
paulson@16905
   341
      
paulson@16905
   342
      (*val numcls_string = numclstr ( vars, numcls) ""*)
paulson@16905
   343
      val _ = File.write (File.tmp_path (Path.basic "foo_axiom")) "got axioms"
paulson@16061
   344
	
paulson@16905
   345
  (************************************)
paulson@16905
   346
  (* translate proof                  *)
paulson@16905
   347
  (************************************)
paulson@16905
   348
      val _ = File.write (File.tmp_path (Path.basic "foo_steps"))                                                                           
paulson@16905
   349
                       ("about to translate proof, steps: "
paulson@16905
   350
                       ^(init_proofsteps_to_string proof_steps ""))
paulson@16905
   351
      val (newthm,proof) = translate_proof numcls  proof_steps vars
paulson@16905
   352
      val _ = File.write (File.tmp_path (Path.basic "foo_steps2"))                                                                       
paulson@16905
   353
                       ("translated proof, steps: "^(init_proofsteps_to_string proof_steps ""))
paulson@16905
   354
  (***************************************************)
paulson@16905
   355
  (* transfer necessary steps as strings to Isabelle *)
paulson@16905
   356
  (***************************************************)
paulson@16905
   357
      (* turn the proof into a string *)
paulson@16905
   358
      val reconProofStr = proofs_to_string proof ""
paulson@16905
   359
      (* do the bit for the Isabelle ordered axioms at the top *)
paulson@16905
   360
      val ax_nums = map #1 numcls
paulson@16905
   361
      val ax_strs = map ReconOrderClauses.get_meta_lits_bracket (map #2 numcls)
paulson@16905
   362
      val numcls_strs = ListPair.zip (ax_nums,ax_strs)
paulson@16905
   363
      val num_cls_vars =  map (addvars vars) numcls_strs;
paulson@16905
   364
      val reconIsaAxStr = origAxs_to_string (ListPair.zip (ax_nums,ax_with_vars)) ""
paulson@16905
   365
      
paulson@16905
   366
      val extra_nums = if (not (extra_with_vars = [])) then (1 upto (length extra_with_vars))
paulson@16905
   367
                       else []
paulson@16905
   368
      val reconExtraAxStr = extraAxs_to_string ( ListPair.zip (extra_nums,extra_with_vars)) ""
paulson@16905
   369
      val frees_str = "["^(thmvars_to_string frees "")^"]"
paulson@16905
   370
      val _ = File.write (File.tmp_path (Path.basic "reconstringfile"))
paulson@16905
   371
                          (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
paulson@16905
   372
      val reconstr = (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
paulson@16905
   373
  in 
paulson@16905
   374
       TextIO.output (toParent, reconstr^"\n");
paulson@16905
   375
       TextIO.flushOut toParent;
paulson@16905
   376
       TextIO.output (toParent, thmstring^"\n");
paulson@16905
   377
       TextIO.flushOut toParent;
paulson@16905
   378
       TextIO.output (toParent, goalstring^"\n");
paulson@16905
   379
       TextIO.flushOut toParent;
quigley@15642
   380
paulson@16905
   381
       Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
paulson@16905
   382
      (* Attempt to prevent several signals from turning up simultaneously *)
paulson@17306
   383
       Posix.Process.sleep(Time.fromSeconds 1) ; all_tac
paulson@16905
   384
  end
paulson@16905
   385
  handle _ => 
paulson@16905
   386
  let val _ = File.write(File.tmp_path (Path.basic "foo_handler")) "In exception handler"
paulson@16905
   387
  in 
paulson@16905
   388
       TextIO.output (toParent,"Proof found but translation failed for resolution proof:"^(remove_linebreaks proofstr) ^"\n");
paulson@16905
   389
      TextIO.flushOut toParent;
paulson@16905
   390
    TextIO.output (toParent, thmstring^"\n");
paulson@16905
   391
       TextIO.flushOut toParent;
paulson@16905
   392
       TextIO.output (toParent, goalstring^"\n");
paulson@16905
   393
       TextIO.flushOut toParent;
paulson@16905
   394
      Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
paulson@16905
   395
      (* Attempt to prevent several signals from turning up simultaneously *)
paulson@17306
   396
      Posix.Process.sleep(Time.fromSeconds 1); all_tac
paulson@16905
   397
  end
quigley@15642
   398
quigley@15642
   399
quigley@15642
   400
(**********************************************************************************)
quigley@15642
   401
(* At other end, want to turn back into datatype so can apply reconstruct_proof.  *)
quigley@15642
   402
(* This will be done by the signal handler                                        *)
quigley@15642
   403
(**********************************************************************************)
quigley@15642
   404
quigley@15642
   405
(* Parse in the string version of the proof steps for reconstruction *)
quigley@15642
   406
(* Isar format: cl1 [BINARY 0 cl2 0];cl1 [PARAMOD 0 cl2 0]; cl1 [DEMOD 0 cl2];cl1 [FACTOR 1 2];*)
quigley@15642
   407
quigley@15642
   408
quigley@15642
   409
 val term_numstep =
quigley@15642
   410
        (number ++ (a (Other ",")) ++ number) >> (fn (a, (_, c)) => (a, c))
quigley@15642
   411
quigley@15642
   412
val extraaxiomstep = (a (Word "ExtraAxiom"))++ (a (Other "(")) ++(a (Other ")"))
quigley@15642
   413
            >> (fn (_) => ExtraAxiom)
quigley@15642
   414
quigley@15642
   415
quigley@15642
   416
quigley@15642
   417
val origaxiomstep = (a (Word "OrigAxiom"))++ (a (Other "(")) ++(a (Other ")"))
quigley@15642
   418
            >> (fn (_) => OrigAxiom)
quigley@15642
   419
quigley@15642
   420
quigley@15642
   421
 val axiomstep = (a (Word "Axiom"))++ (a (Other "(")) ++(a (Other ")"))
quigley@15642
   422
            >> (fn (_) => Axiom)
quigley@15642
   423
     
quigley@15642
   424
quigley@15642
   425
quigley@15642
   426
      
quigley@15642
   427
 val binarystep = (a (Word "Binary")) ++ (a (Other "(")) ++ (a (Other "(")) 
quigley@15642
   428
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
quigley@15642
   429
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
quigley@15642
   430
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Binary (c,e))
quigley@15642
   431
      
quigley@15642
   432
quigley@15642
   433
 val parastep = (a (Word "Para")) ++ (a (Other "(")) ++ (a (Other "(")) 
quigley@15642
   434
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
quigley@15642
   435
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
quigley@15642
   436
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Para(c, e))
quigley@15642
   437
      
quigley@15642
   438
 val mrrstep = (a (Word "MRR")) ++ (a (Other "(")) ++ (a (Other "(")) 
quigley@15642
   439
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
quigley@15642
   440
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
quigley@15642
   441
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => MRR(c, e))
quigley@15642
   442
      
quigley@15642
   443
quigley@15642
   444
 val factorstep = (a (Word "Factor")) ++ (a (Other "("))
quigley@15642
   445
                    ++ number ++ (a (Other ","))
quigley@15642
   446
                       ++ number ++ (a (Other ","))
quigley@15642
   447
                       ++ number ++  (a (Other ")"))
quigley@15642
   448
                   
quigley@15642
   449
            >> (fn (_, (_, (c, (_, (e,(_,(f,_))))))) =>  Factor (c,e,f))
quigley@15642
   450
quigley@15642
   451
quigley@16548
   452
(*val rewritestep = (a (Word "Rewrite"))  ++ (a (Other "(")) ++ (a (Other "(")) 
quigley@15642
   453
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
quigley@15642
   454
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
quigley@16548
   455
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Rewrite (c,e))*)
quigley@15642
   456
quigley@15642
   457
val obviousstep = (a (Word "Obvious")) ++ (a (Other "(")) 
quigley@15642
   458
                   ++ term_numstep  ++ (a (Other ")")) 
quigley@15642
   459
            >> (fn (_, (_, (c,_))) => Obvious (c))
quigley@15642
   460
quigley@16548
   461
 val methodstep = extraaxiomstep || origaxiomstep || axiomstep ||binarystep || factorstep|| parastep || mrrstep || (*rewritestep ||*) obviousstep
quigley@15642
   462
quigley@15642
   463
quigley@15642
   464
 val number_list_step =
paulson@15739
   465
        ( number ++ many ((a (Other ",") ++ number)>> #2))
quigley@15642
   466
        >> (fn (a,b) => (a::b))
quigley@15642
   467
        
quigley@15642
   468
 val numberlist_step = a (Other "[")  ++ a (Other "]")
quigley@15642
   469
                        >>(fn (_,_) => ([]:int list))
quigley@15642
   470
                       || a (Other "[") ++ number_list_step ++ a (Other "]")
quigley@15642
   471
                        >>(fn (_,(a,_)) => a)
quigley@15642
   472
                    
quigley@15642
   473
quigley@15642
   474
quigley@15642
   475
(** change this to allow P (x U) *)
paulson@17306
   476
 fun arglist_step input = 
paulson@17306
   477
   ( word ++ many word >> (fn (a, b) => (a^" "^(space_implode " " b)))
paulson@17306
   478
    ||word >> (fn (a) => (a)))input
quigley@15642
   479
                
quigley@15642
   480
quigley@15642
   481
fun literal_step input = (word ++ a (Other "(") ++ arglist_step ++  a (Other ")")
quigley@15642
   482
                                          >>(fn (a, (b, (c,d))) => (a^" ("^(c)^")"))
quigley@15642
   483
                        || arglist_step >> (fn (a) => (a)))input
quigley@15642
   484
                           
quigley@15642
   485
quigley@15642
   486
quigley@15642
   487
(* fun term_step input = (a (Other "~") ++ arglist_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
quigley@15642
   488
                     ||  arglist_step ++ a (Other "%")>> (fn (a,b) => a ))input
quigley@15642
   489
*)
quigley@15642
   490
quigley@15642
   491
quigley@15642
   492
 fun term_step input = (a (Other "~") ++ literal_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
quigley@15642
   493
                     ||  literal_step ++ a (Other "%")>> (fn (a,b) => a ))input
quigley@15642
   494
quigley@15642
   495
quigley@15642
   496
         
quigley@15642
   497
quigley@15642
   498
 val term_list_step =
quigley@15642
   499
        (  term_step ++ many ( term_step))
quigley@15642
   500
        >> (fn (a,b) => (a::b))
quigley@15642
   501
        
quigley@15642
   502
 
quigley@15642
   503
val term_lists_step = a (Other "[")  ++ a (Other "]")
quigley@15642
   504
                        >>(fn (_,_) => ([]:string list))
quigley@15642
   505
                       || a (Other "[") ++ term_list_step ++ a (Other "]")
quigley@15642
   506
                        >>(fn (_,(a,_)) => a)
quigley@15642
   507
                     
quigley@15642
   508
quigley@15642
   509
quigley@15642
   510
quigley@15642
   511
fun anytoken_step input  = (word>> (fn (a) => a)  ) input
quigley@15642
   512
                       handle NOPARSE_WORD => (number>> (fn (a) => string_of_int a)  ) input
quigley@15642
   513
                      handle NOPARSE_NUMBER => (other_char >> (fn(a) => a)) input
quigley@15642
   514
quigley@15642
   515
quigley@15642
   516
quigley@15642
   517
fun goalstring_step input= (anytoken_step ++ many (anytoken_step )
quigley@15642
   518
                  >> (fn (a,b) =>  (a^" "^(implode b)))) input
quigley@15642
   519
quigley@15642
   520
quigley@15642
   521
quigley@15642
   522
 val linestep = number ++ methodstep ++ term_lists_step ++ term_lists_step
quigley@15642
   523
                >> (fn (a, (b, (c,d))) => (a,(b,c,d)))
quigley@15642
   524
    
quigley@15642
   525
 val lines_step = many linestep
quigley@15642
   526
paulson@15739
   527
 val alllines_step = (term_lists_step ++ lines_step ) ++ finished >> #1
quigley@15642
   528
    
paulson@15739
   529
 val parse_step = #1 o alllines_step
quigley@15642
   530
quigley@15642
   531
quigley@15642
   532
 (*
quigley@15642
   533
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)"
quigley@15642
   534
*)
quigley@15642
   535
quigley@15642
   536
(************************************************************)
quigley@15642
   537
(* Construct an Isar style proof from a list of proof steps *)
quigley@15642
   538
(************************************************************)
quigley@15642
   539
(* want to assume all axioms, then do haves for the other clauses*)
quigley@15642
   540
(* then show for the last step *)
quigley@15642
   541
quigley@15642
   542
(* replace ~ by not here *)
paulson@17317
   543
val change_nots = String.translate (fn c => if c = #"~" then "\\<not>" else str c);
quigley@15642
   544
paulson@17317
   545
fun clstrs_to_string xs = space_implode "; " (map change_nots xs);
quigley@15642
   546
quigley@15642
   547
fun thmvars_to_quantstring [] str = str
quigley@15642
   548
|   thmvars_to_quantstring (x::[]) str =str^x^". "
quigley@15642
   549
|   thmvars_to_quantstring (x::xs) str = thmvars_to_quantstring xs (str^(x^" "))
quigley@15642
   550
quigley@15642
   551
paulson@17317
   552
fun clause_strs_to_isar clstrs [] =
paulson@17317
   553
      "\"\\<lbrakk>"^(clstrs_to_string clstrs)^"\\<rbrakk> \\<Longrightarrow> False\""
paulson@17317
   554
|   clause_strs_to_isar clstrs thmvars =
paulson@17317
   555
      "\"\\<And>"^(thmvars_to_quantstring thmvars "")^
paulson@17317
   556
      "\\<lbrakk>"^(clstrs_to_string clstrs)^"\\<rbrakk> \\<Longrightarrow> False\""
quigley@15642
   557
paulson@17317
   558
fun frees_to_isar_str clstrs = space_implode " " (map change_nots clstrs)
quigley@15642
   559
quigley@15642
   560
quigley@15642
   561
(***********************************************************************)
quigley@15642
   562
(* functions for producing assumptions for the Isabelle ordered axioms *)
quigley@15642
   563
(***********************************************************************)
quigley@15642
   564
(*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))[][]";       
quigley@15642
   565
num, rule, clausestrs, vars*)
quigley@15642
   566
quigley@15642
   567
quigley@15642
   568
(* assume the extra clauses - not used in Spass proof *)
quigley@15642
   569
quigley@15642
   570
fun is_extraaxiom_step ( num:int,(ExtraAxiom, str, tstr)) = true
quigley@15642
   571
|   is_extraaxiom_step (num, _) = false
quigley@15642
   572
quigley@15642
   573
fun get_extraaxioms xs = List.filter (is_extraaxiom_step) ( xs)
quigley@15642
   574
quigley@15642
   575
fun assume_isar_extraaxiom [] str  = str
quigley@15642
   576
|   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 " )
quigley@15642
   577
quigley@15642
   578
quigley@15642
   579
quigley@15642
   580
fun assume_isar_extraaxioms  [] = ""
quigley@15642
   581
|assume_isar_extraaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n" 
quigley@15642
   582
                                         in
quigley@15642
   583
                                             assume_isar_extraaxiom xs str
quigley@15642
   584
                                         end
quigley@15642
   585
quigley@15642
   586
(* assume the Isabelle ordered clauses *)
quigley@15642
   587
quigley@15642
   588
fun is_origaxiom_step ( num:int,(OrigAxiom, str, tstr)) = true
quigley@15642
   589
|   is_origaxiom_step (num, _) = false
quigley@15642
   590
quigley@15642
   591
fun get_origaxioms xs = List.filter (is_origaxiom_step) ( xs)
quigley@15642
   592
quigley@15642
   593
fun assume_isar_origaxiom [] str  = str
quigley@15642
   594
|   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 " )
quigley@15642
   595
quigley@15642
   596
quigley@15642
   597
quigley@15642
   598
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" 
quigley@15642
   599
                                         in
quigley@15642
   600
                                             assume_isar_origaxiom xs str
quigley@15642
   601
                                         end
quigley@15642
   602
quigley@15642
   603
quigley@15642
   604
quigley@15642
   605
fun is_axiom_step ( num:int,(Axiom, str, tstr)) = true
quigley@15642
   606
|   is_axiom_step (num, _) = false
quigley@15642
   607
quigley@15642
   608
fun get_axioms xs = List.filter  (is_axiom_step) ( xs)
quigley@15642
   609
quigley@15642
   610
fun have_isar_axiomline (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
quigley@15642
   611
quigley@15642
   612
fun  by_isar_axiomline (numb,(step, clstrs, thmstrs))="by (rule cl"^ (string_of_int numb)^"') \n"
quigley@15642
   613
quigley@15642
   614
quigley@15642
   615
fun isar_axiomline (numb, (step, clstrs, thmstrs))  = (have_isar_axiomline (numb,(step,clstrs, thmstrs )))^( by_isar_axiomline(numb,(step,clstrs, thmstrs )) )
quigley@15642
   616
quigley@15642
   617
quigley@15642
   618
fun isar_axiomlines [] str = str
quigley@15642
   619
|   isar_axiomlines (x::xs) str = isar_axiomlines xs (str^(isar_axiomline x))
quigley@15642
   620
quigley@15642
   621
quigley@15642
   622
fun have_isar_line (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
quigley@16357
   623
(*FIX: ask Larry to add and mrr attribute *)
quigley@15642
   624
paulson@16091
   625
fun by_isar_line ((Binary ((a,b), (c,d)))) = 
paulson@16091
   626
    "by(rule cl"^
paulson@16091
   627
		(string_of_int a)^" [binary "^(string_of_int b)^" cl"^
paulson@16091
   628
		(string_of_int c)^" "^(string_of_int d)^"])\n"
quigley@16357
   629
|by_isar_line ((MRR ((a,b), (c,d)))) = 
quigley@16357
   630
    "by(rule cl"^
quigley@16357
   631
		(string_of_int a)^" [binary "^(string_of_int b)^" cl"^
quigley@16357
   632
		(string_of_int c)^" "^(string_of_int d)^"])\n"
paulson@16091
   633
|   by_isar_line ( (Para ((a,b), (c,d)))) =
paulson@16091
   634
    "by (rule cl"^
paulson@16091
   635
		(string_of_int a)^" [paramod "^(string_of_int b)^" cl"^
paulson@16091
   636
		(string_of_int c)^" "^(string_of_int d)^"])\n"
paulson@16091
   637
|   by_isar_line ((Factor ((a,b,c)))) = 
paulson@16091
   638
    "by (rule cl"^(string_of_int a)^" [factor "^(string_of_int b)^" "^
paulson@16091
   639
		(string_of_int c)^" ])\n"
quigley@16548
   640
(*|   by_isar_line ( (Rewrite ((a,b),(c,d)))) =
paulson@16091
   641
    "by (rule cl"^(string_of_int a)^" [demod "^(string_of_int b)^" "^
quigley@16548
   642
		(string_of_int c)^" "^(string_of_int d)^" ])\n"*)
paulson@16091
   643
|   by_isar_line ( (Obvious ((a,b)))) =
paulson@16091
   644
    "by (rule cl"^(string_of_int a)^" [obvious "^(string_of_int b)^" ])\n"
quigley@15642
   645
quigley@15642
   646
fun isar_line (numb, (step, clstrs, thmstrs))  = (have_isar_line (numb,(step,clstrs, thmstrs )))^( by_isar_line step)
quigley@15642
   647
quigley@15642
   648
quigley@15642
   649
fun isar_lines [] str = str
quigley@15642
   650
|   isar_lines (x::xs) str = isar_lines xs (str^(isar_line x))
quigley@15642
   651
quigley@15642
   652
fun last_isar_line (numb,( step, clstrs,thmstrs)) = "show \"False\"\n"^(by_isar_line step)
quigley@15642
   653
quigley@15642
   654
paulson@16091
   655
fun to_isar_proof (frees, xs, goalstring) =
paulson@16091
   656
    let val extraaxioms = get_extraaxioms xs
paulson@16091
   657
	val extraax_num = length extraaxioms
paulson@16091
   658
	val origaxioms_and_steps = Library.drop (extraax_num, xs)  
paulson@16091
   659
	
paulson@16091
   660
	val origaxioms = get_origaxioms origaxioms_and_steps
paulson@16091
   661
	val origax_num = length origaxioms
paulson@16091
   662
	val axioms_and_steps = Library.drop (origax_num + extraax_num, xs)  
paulson@16091
   663
	val axioms = get_axioms axioms_and_steps
paulson@16091
   664
	
paulson@16091
   665
	val steps = Library.drop (origax_num, axioms_and_steps)
paulson@16091
   666
	val firststeps = ReconOrderClauses.butlast steps
paulson@17312
   667
	val laststep = List.last steps
paulson@16091
   668
	val goalstring = implode(ReconOrderClauses.butlast(explode goalstring))
paulson@16091
   669
	
paulson@16091
   670
	val isar_proof = 
paulson@16091
   671
		("show \""^goalstring^"\"\n")^
paulson@16091
   672
		("proof (rule ccontr,skolemize, make_clauses) \n")^
paulson@16091
   673
		("fix "^(frees_to_isar_str frees)^"\n")^
paulson@16091
   674
		(assume_isar_extraaxioms extraaxioms)^
paulson@16091
   675
		(assume_isar_origaxioms origaxioms)^
paulson@16091
   676
		(isar_axiomlines axioms "")^
paulson@16091
   677
		(isar_lines firststeps "")^
paulson@16091
   678
		(last_isar_line laststep)^
paulson@16091
   679
		("qed")
paulson@16905
   680
	val _ = File.write (File.tmp_path (Path.basic "isar_proof_file")) isar_proof
paulson@16091
   681
    in
paulson@16091
   682
	isar_proof
paulson@16091
   683
    end;
quigley@15642
   684
quigley@15642
   685
(* get fix vars from axioms - all Frees *)
quigley@15642
   686
(* check each clause for meta-vars and /\ over them at each step*)
quigley@15642
   687
quigley@15642
   688
(*******************************************************)
quigley@15642
   689
(* This assumes the thm list  "numcls" is still there  *)
quigley@15642
   690
(* In reality, should probably label it with an        *)
quigley@15642
   691
(* ID number identifying the subgoal.  This could      *)
quigley@15642
   692
(* be passed over to the watcher, e.g.  numcls25       *)
quigley@15642
   693
(*******************************************************)
quigley@15642
   694
paulson@17315
   695
fun apply_res_thm str goalstring  = 
paulson@17315
   696
  let val tokens = #1 (lex str);
paulson@17315
   697
      val _ = File.append (File.tmp_path (Path.basic "apply_res_1")) 
paulson@17315
   698
	 ("str is: "^str^" goalstr is: "^goalstring^"\n")	
paulson@17315
   699
      val (frees,recon_steps) = parse_step tokens 
paulson@17315
   700
      val isar_str = to_isar_proof (frees, recon_steps, goalstring)
paulson@17315
   701
      val foo = File.write (File.tmp_path (Path.basic "apply_res_2")) isar_str
paulson@17315
   702
  in 
paulson@17315
   703
     Pretty.writeln(Pretty.str isar_str)
paulson@17315
   704
  end 
quigley@15642
   705
paulson@15684
   706
end;