src/HOL/Tools/ATP/recon_translate_proof.ML
author paulson
Tue May 24 10:23:24 2005 +0200 (2005-05-24)
changeset 16061 8a139c1557bf
parent 15919 b30a35432f5a
child 16157 1764cc98bafd
permissions -rw-r--r--
A new structure and reduced indentation
paulson@15789
     1
(*  ID:         $Id$
paulson@15789
     2
    Author:     Claire Quigley
paulson@15789
     3
    Copyright   2004  University of Cambridge
paulson@15789
     4
*)
quigley@15642
     5
quigley@15642
     6
fun add_in_order (x:string) [] = [x]
quigley@15642
     7
|   add_in_order (x:string) ((y:string)::ys) = if (x < y) 
quigley@15642
     8
                             then 
quigley@15642
     9
                                  (x::(y::ys))
quigley@15642
    10
                             else
quigley@15642
    11
                                  (y::(add_in_order x ys))
quigley@15642
    12
fun add_once x [] = [x]
quigley@15642
    13
|   add_once x (y::ys) = if (inlist x (y::ys)) then 
quigley@15642
    14
                            (y::ys)
quigley@15642
    15
                        else
quigley@15642
    16
                            add_in_order x (y::ys)
quigley@15642
    17
     
paulson@15684
    18
fun thm_vars thm = map (fn ((name,ix),_) => name) (Drule.vars_of thm);
quigley@15642
    19
quigley@15642
    20
Goal "False ==> False";
quigley@15642
    21
by Auto_tac;
quigley@15642
    22
qed "False_imp";
quigley@15642
    23
quigley@15642
    24
exception Reflex_equal;
quigley@15642
    25
quigley@15642
    26
(********************************)
quigley@15642
    27
(* Proofstep datatype           *)
quigley@15642
    28
(********************************)
quigley@15642
    29
(* Assume rewrite steps have only two clauses in them just now, but lcl109-5 has Rew[5,3,5,3]  *)
quigley@15642
    30
quigley@15642
    31
datatype Side = Left |Right
quigley@15642
    32
quigley@15642
    33
 datatype Proofstep = ExtraAxiom
quigley@15642
    34
                     |OrigAxiom
quigley@15642
    35
                     | Axiom
quigley@15642
    36
                     | Binary of (int * int) * (int * int)   (* (clause1,lit1), (clause2, lit2) *)
quigley@15642
    37
                     | MRR of (int * int) * (int * int) 
quigley@15642
    38
                     | Factor of (int * int * int)           (* (clause,lit1, lit2) *)
quigley@15642
    39
                     | Para of (int * int) * (int * int) 
quigley@15642
    40
                     | Rewrite of (int * int) * (int * int)  
quigley@15642
    41
                     | Obvious of (int * int)
quigley@15642
    42
                     (*| Hyper of int list*)
quigley@15642
    43
                     | Unusedstep of unit
quigley@15642
    44
quigley@15642
    45
quigley@15642
    46
datatype Clausesimp = Binary_s of int * int
quigley@15642
    47
                      | Factor_s of unit
quigley@15642
    48
                      | Demod_s of (int * int) list
quigley@15642
    49
                      | Hyper_s of int list
quigley@15642
    50
                      | Unusedstep_s of unit
quigley@15642
    51
quigley@15642
    52
quigley@15642
    53
quigley@15642
    54
datatype Step_label = T_info
quigley@15642
    55
                     |P_info
quigley@15642
    56
quigley@15642
    57
paulson@16061
    58
fun is_alpha_space_digit_or_neg ch =
paulson@16061
    59
    (ch = "~") orelse (ReconOrderClauses.is_alpha ch) orelse 
paulson@16061
    60
    (ReconOrderClauses.is_digit ch) orelse ( ch = " ");
quigley@15642
    61
quigley@15642
    62
paulson@15697
    63
fun lit_string_with_nums t = let val termstr = Term.string_of_term t
quigley@15642
    64
                                 val exp_term = explode termstr
quigley@15642
    65
                             in
quigley@15642
    66
                                 implode(List.filter is_alpha_space_digit_or_neg exp_term)
quigley@15642
    67
                             end
quigley@15642
    68
paulson@15774
    69
fun reconstruction_failed fname = error (fname ^ ": reconstruction failed")
quigley@15642
    70
quigley@15919
    71
(************************************************)
quigley@15919
    72
(* Reconstruct an axiom resolution step         *)
quigley@15919
    73
(* clauses is a list of (clausenum,clause) pairs*)
quigley@15919
    74
(************************************************)
quigley@15642
    75
paulson@15774
    76
fun follow_axiom clauses  allvars (clausenum:int) thml clause_strs =  
paulson@16061
    77
    let val this_axiom = valOf (assoc (clauses,clausenum))
paulson@16061
    78
	val (res, numlist, symlist, nsymlist) = (ReconOrderClauses.rearrange_clause this_axiom clause_strs allvars)         
paulson@16061
    79
	val thmvars = thm_vars res
paulson@16061
    80
    in
paulson@16061
    81
	(res, (Axiom,clause_strs,thmvars )  )
paulson@16061
    82
    end
paulson@16061
    83
    handle Option => reconstruction_failed "follow_axiom"
quigley@15642
    84
quigley@15642
    85
(****************************************)
quigley@15642
    86
(* Reconstruct a binary resolution step *)
quigley@15642
    87
(****************************************)
quigley@15642
    88
quigley@15642
    89
                 (* numbers of clauses and literals*) (*vars*) (*list of current thms*) (* literal strings as parsed from spass *)
paulson@16061
    90
fun follow_binary ((clause1, lit1), (clause2 , lit2)) allvars thml clause_strs =
paulson@16061
    91
    let val thm1 =  select_literal (lit1 + 1) (valOf (assoc (thml,clause1)))
paulson@16061
    92
	val thm2 =  valOf (assoc (thml,clause2))
paulson@16061
    93
	val res =   thm1 RSN ((lit2 +1), thm2)
paulson@16061
    94
	val (res', numlist, symlist, nsymlist) = (ReconOrderClauses.rearrange_clause res clause_strs allvars)
paulson@16061
    95
	val thmvars = thm_vars res
paulson@16061
    96
    in
paulson@16061
    97
       (res',  ((Binary ((clause1, lit1), (clause2 , lit2))),clause_strs,thmvars) )
paulson@16061
    98
    end
paulson@16061
    99
    handle Option => reconstruction_failed "follow_binary"
quigley@15642
   100
quigley@15642
   101
quigley@15642
   102
quigley@15642
   103
(******************************************************)
quigley@15642
   104
(* Reconstruct a matching replacement resolution step *)
quigley@15642
   105
(******************************************************)
quigley@15642
   106
quigley@15642
   107
paulson@16061
   108
fun follow_mrr ((clause1, lit1), (clause2 , lit2))  allvars thml clause_strs =
paulson@16061
   109
    let val thm1 =  select_literal (lit1 + 1) (valOf (assoc (thml,clause1)))
paulson@16061
   110
	val thm2 =  valOf (assoc (thml,clause2))
paulson@16061
   111
	val res =   thm1 RSN ((lit2 +1), thm2)
paulson@16061
   112
	val (res', numlist, symlist, nsymlist) = 
paulson@16061
   113
	    (ReconOrderClauses.rearrange_clause res clause_strs allvars)
paulson@16061
   114
	val thmvars = thm_vars res
paulson@16061
   115
    in
paulson@16061
   116
       (res',  ((MRR ((clause1, lit1), (clause2 , lit2))) ,clause_strs,thmvars))
paulson@16061
   117
    end
paulson@16061
   118
    handle Option => reconstruction_failed "follow_mrr"
quigley@15642
   119
quigley@15642
   120
quigley@15642
   121
(*******************************************)
quigley@15642
   122
(* Reconstruct a factoring resolution step *)
quigley@15642
   123
(*******************************************)
quigley@15642
   124
quigley@15642
   125
fun mksubstlist [] sublist = sublist
paulson@16061
   126
   |mksubstlist ((a, (_, b)) :: rest) sublist = 
paulson@16061
   127
       let val vartype = type_of b 
paulson@16061
   128
	   val avar = Var(a,vartype)
paulson@16061
   129
	   val newlist = ((avar,b)::sublist)
paulson@16061
   130
       in
paulson@16061
   131
	   mksubstlist rest newlist
paulson@16061
   132
       end;
quigley@15642
   133
quigley@15642
   134
(* based on Tactic.distinct_subgoals_tac *)
quigley@15642
   135
quigley@15642
   136
fun delete_assump_tac state lit =
quigley@15642
   137
    let val (frozth,thawfn) = freeze_thaw state
quigley@15642
   138
        val froz_prems = cprems_of frozth
quigley@15642
   139
        val assumed = implies_elim_list frozth (map assume froz_prems)
paulson@16061
   140
        val new_prems = ReconOrderClauses.remove_nth lit froz_prems
quigley@15642
   141
        val implied = implies_intr_list new_prems assumed
quigley@15642
   142
    in  
quigley@15642
   143
        Seq.single (thawfn implied)  
quigley@15642
   144
    end
quigley@15642
   145
quigley@15642
   146
quigley@15642
   147
quigley@15642
   148
quigley@15642
   149
quigley@15642
   150
(*************************************)
quigley@15642
   151
(* Reconstruct a factoring step      *)
quigley@15642
   152
(*************************************)
quigley@15642
   153
paulson@15739
   154
(*FIXME: share code with that in Tools/reconstruction.ML*)
paulson@16061
   155
fun follow_factor clause lit1 lit2 allvars thml clause_strs = 
paulson@16061
   156
    let 
paulson@16061
   157
      val th =  valOf (assoc (thml,clause))
paulson@16061
   158
      val prems = prems_of th
paulson@16061
   159
      val sign = sign_of_thm th
paulson@16061
   160
      val fac1 = ReconOrderClauses.get_nth (lit1+1) prems
paulson@16061
   161
      val fac2 = ReconOrderClauses.get_nth (lit2+1) prems
paulson@16061
   162
      val unif_env = Unify.unifiers (sign,Envir.empty 0, [(fac1, fac2)])
paulson@16061
   163
      val newenv = getnewenv unif_env
paulson@16061
   164
      val envlist = Envir.alist_of newenv
paulson@16061
   165
      
paulson@16061
   166
      val (t1,t2)::_ = mksubstlist envlist []
paulson@16061
   167
    in 
paulson@16061
   168
      if (is_Var t1)
paulson@16061
   169
      then
paulson@16061
   170
	  let 
paulson@16061
   171
	     val str1 = lit_string_with_nums t1;
paulson@16061
   172
	     val str2 = lit_string_with_nums t2;
paulson@16061
   173
	     val facthm = read_instantiate [(str1,str2)] th;
paulson@16061
   174
	     val res = hd (Seq.list_of(delete_assump_tac  facthm (lit1 + 1)))
paulson@16061
   175
	     val (res', numlist, symlist, nsymlist) = 
paulson@16061
   176
	         ReconOrderClauses.rearrange_clause res clause_strs allvars
paulson@16061
   177
	     val thmvars = thm_vars res'
paulson@16061
   178
	  in 
paulson@16061
   179
		 (res',((Factor (clause,  lit1, lit2)),clause_strs,thmvars))
paulson@16061
   180
	  end
paulson@16061
   181
      else
paulson@16061
   182
	  let
paulson@16061
   183
	     val str2 = lit_string_with_nums t1;
paulson@16061
   184
	     val str1 = lit_string_with_nums t2;
paulson@16061
   185
	     val facthm = read_instantiate [(str1,str2)] th;
paulson@16061
   186
	     val res = hd (Seq.list_of(delete_assump_tac  facthm (lit1 + 1)))
paulson@16061
   187
	     val (res', numlist, symlist, nsymlist) = 
paulson@16061
   188
	         ReconOrderClauses.rearrange_clause res clause_strs allvars
paulson@16061
   189
	     val thmvars = thm_vars res'
paulson@16061
   190
	  in 
paulson@16061
   191
		 (res', ((Factor (clause,  lit1, lit2)),clause_strs, thmvars))         
paulson@16061
   192
	  end
paulson@16061
   193
   end
paulson@16061
   194
   handle Option => reconstruction_failed "follow_factor"
quigley@15642
   195
quigley@15642
   196
quigley@15642
   197
paulson@15684
   198
fun get_unif_comb t eqterm =
paulson@15684
   199
    if ((type_of t) = (type_of eqterm))
paulson@15684
   200
    then t
paulson@15684
   201
    else
paulson@15684
   202
        let val _ $ rand = t
paulson@15684
   203
        in get_unif_comb rand eqterm end;
quigley@15642
   204
paulson@15684
   205
fun get_unif_lit t eqterm =
paulson@15684
   206
    if (can HOLogic.dest_eq t)
paulson@15684
   207
    then
paulson@15684
   208
	let val (lhs,rhs) = HOLogic.dest_eq(HOLogic.dest_Trueprop eqterm)
paulson@15684
   209
	in lhs end
paulson@15684
   210
    else
paulson@15684
   211
	get_unif_comb t eqterm;
paulson@15684
   212
quigley@15642
   213
quigley@15642
   214
quigley@15642
   215
(*************************************)
quigley@15642
   216
(* Reconstruct a paramodulation step *)
quigley@15642
   217
(*************************************)
quigley@15642
   218
quigley@15642
   219
val rev_subst = rotate_prems 1 subst;
quigley@15642
   220
val rev_ssubst = rotate_prems 1 ssubst;
quigley@15642
   221
quigley@15642
   222
paulson@16061
   223
fun follow_standard_para ((clause1, lit1), (clause2 , lit2)) allvars thml clause_strs = 
paulson@16061
   224
    let 
paulson@16061
   225
      val th1 =  valOf (assoc (thml,clause1))
paulson@16061
   226
      val th2 =  valOf (assoc (thml,clause2)) 
paulson@16061
   227
      val eq_lit_th = select_literal (lit1+1) th1
paulson@16061
   228
      val mod_lit_th = select_literal (lit2+1) th2
paulson@16061
   229
      val eqsubst = eq_lit_th RSN (2,rev_subst)
paulson@16061
   230
      val newth = Seq.hd (biresolution false [(false, mod_lit_th)] 1 eqsubst)
paulson@16061
   231
      val newth' =negate_head newth 
paulson@16061
   232
      val (res, numlist, symlist, nsymlist)  = 
paulson@16061
   233
          (ReconOrderClauses.rearrange_clause newth' clause_strs allvars 
paulson@16061
   234
	   handle Not_in_list => 
paulson@16061
   235
	       let val mod_lit_th' = mod_lit_th RS not_sym
paulson@16061
   236
		   val newth = Seq.hd (biresolution false [(false, mod_lit_th')] 1 eqsubst)
paulson@16061
   237
		   val newth' =negate_head newth 
paulson@16061
   238
		in 
paulson@16061
   239
		   ReconOrderClauses.rearrange_clause newth' clause_strs allvars
paulson@16061
   240
		end)
paulson@16061
   241
      val thmvars = thm_vars res
paulson@16061
   242
   in 
paulson@16061
   243
     (res, ((Para((clause1, lit1), (clause2 , lit2))),clause_strs,thmvars))
paulson@16061
   244
   end
paulson@16061
   245
   handle Option => reconstruction_failed "follow_standard_para"
quigley@15642
   246
quigley@15642
   247
(*              
quigley@15642
   248
fun follow_standard_para ((clause1, lit1), (clause2 , lit2)) allvars thml clause_strs= 
quigley@15642
   249
                          let 
paulson@15774
   250
                            val th1 =  valOf (assoc (thml,clause1))
paulson@15774
   251
                            val th2 =  valOf (assoc (thml,clause2)) 
quigley@15642
   252
                            val eq_lit_th = select_literal (lit1+1) th1
quigley@15642
   253
                            val mod_lit_th = select_literal (lit2+1) th2
quigley@15642
   254
                            val eqsubst = eq_lit_th RSN (2,rev_subst)
quigley@15642
   255
                            val newth = Seq.hd (biresolution false [(false, mod_lit_th)] 1 eqsubst)
quigley@15642
   256
			    val newth' =negate_nead newth 
quigley@15642
   257
                            val (res, numlist, symlist, nsymlist)  = (rearrange_clause newth' clause_strs allvars)
quigley@15642
   258
                            val thmvars = thm_vars res
quigley@15642
   259
                         in 
quigley@15642
   260
                           (res, ((Para((clause1, lit1), (clause2 , lit2))),clause_strs,thmvars))
quigley@15642
   261
                         end
paulson@15774
   262
			 handle Option => reconstruction_failed "follow_standard_para"
quigley@15642
   263
quigley@15642
   264
*)
quigley@15642
   265
quigley@15642
   266
quigley@15642
   267
(********************************)
quigley@15642
   268
(* Reconstruct a rewriting step *)
quigley@15642
   269
(********************************)
quigley@15642
   270
 
quigley@15642
   271
(*
quigley@15642
   272
quigley@15642
   273
val rev_subst = rotate_prems 1 subst;
quigley@15642
   274
quigley@15642
   275
fun paramod_rule ((cl1, lit1), (cl2 , lit2)) =
quigley@15642
   276
     let  val eq_lit_th = select_literal (lit1+1) cl1
quigley@15642
   277
          val mod_lit_th = select_literal (lit2+1) cl2
quigley@15642
   278
          val eqsubst = eq_lit_th RSN (2,rev_subst)
quigley@15642
   279
          val newth = Seq.hd (biresolution false [(false, mod_lit_th)] 1 
quigley@15642
   280
eqsubst)
paulson@15697
   281
     in Meson.negated_asm_of_head newth end;
quigley@15642
   282
quigley@15642
   283
val newth = Seq.hd (biresolution false [(false, mod_lit_th)] 1 
quigley@15642
   284
eqsubst)
quigley@15642
   285
quigley@15642
   286
val mod_lit_th' = mod_lit_th RS not_sym
quigley@15642
   287
quigley@15642
   288
*)
quigley@15642
   289
quigley@15642
   290
quigley@15642
   291
fun delete_assumps 0 th = th 
quigley@15642
   292
|   delete_assumps n th = let val th_prems = length (prems_of th)
quigley@15642
   293
                              val th' = hd (Seq.list_of(delete_assump_tac  th (th_prems -1)))
quigley@15642
   294
                          in
quigley@15642
   295
                              delete_assumps (n-1) th'
quigley@15642
   296
                          end
quigley@15642
   297
quigley@15642
   298
(* extra conditions from the equality turn up as 2nd to last literals of result.  Need to delete them *)
quigley@15642
   299
(* changed negate_nead to negate_head here too*)
quigley@15642
   300
                    (* clause1, lit1 is thing to rewrite with *)
paulson@16061
   301
fun follow_rewrite ((clause1, lit1), (clause2, lit2)) allvars thml clause_strs = 
paulson@16061
   302
      let val th1 =  valOf (assoc (thml,clause1))
paulson@16061
   303
	  val th2 = valOf (assoc (thml,clause2))
paulson@16061
   304
	  val eq_lit_th = select_literal (lit1+1) th1
paulson@16061
   305
	  val mod_lit_th = select_literal (lit2+1) th2
paulson@16061
   306
	  val eqsubst = eq_lit_th RSN (2,rev_subst)
paulson@16061
   307
	  val eq_lit_prem_num = length (prems_of eq_lit_th)
paulson@16061
   308
	  val sign = Sign.merge (sign_of_thm th1, sign_of_thm th2)
paulson@16061
   309
	  val newth = Seq.hd (biresolution false [(false, mod_lit_th)] 1 eqsubst)
paulson@16061
   310
     	  val newthm = negate_head newth
paulson@16061
   311
	  val newthm' = delete_assumps eq_lit_prem_num newthm
paulson@16061
   312
	  val (res, numlist, symlist, nsymlist) =
paulson@16061
   313
	      ReconOrderClauses.rearrange_clause newthm clause_strs allvars
paulson@16061
   314
	  val thmvars = thm_vars res
paulson@16061
   315
       in
paulson@16061
   316
	   (res, ((Rewrite ((clause1, lit1),  (clause2, lit2))),clause_strs,thmvars))
paulson@16061
   317
       end
paulson@16061
   318
       handle Option => reconstruction_failed "follow_rewrite"
quigley@15642
   319
quigley@15642
   320
quigley@15642
   321
quigley@15642
   322
(*****************************************)
quigley@15642
   323
(* Reconstruct an obvious reduction step *)
quigley@15642
   324
(*****************************************)
quigley@15642
   325
quigley@15642
   326
paulson@16061
   327
fun follow_obvious  (clause1, lit1)  allvars thml clause_strs = 
paulson@16061
   328
    let val th1 =  valOf (assoc (thml,clause1))
paulson@16061
   329
	val prems1 = prems_of th1
paulson@16061
   330
	val newthm = refl RSN ((lit1+ 1), th1)
paulson@16061
   331
		     handle THM _ =>  hd (Seq.list_of(delete_assump_tac  th1 (lit1 + 1)))
paulson@16061
   332
	val (res, numlist, symlist, nsymlist) =
paulson@16061
   333
	    ReconOrderClauses.rearrange_clause newthm clause_strs allvars
paulson@16061
   334
	val thmvars = thm_vars res
paulson@16061
   335
    in 
paulson@16061
   336
	(res, ((Obvious (clause1, lit1)),clause_strs,thmvars))
paulson@16061
   337
    end
paulson@16061
   338
    handle Option => reconstruction_failed "follow_obvious"
quigley@15642
   339
quigley@15642
   340
(**************************************************************************************)
quigley@15642
   341
(* reconstruct a single line of the res. proof - depending on what sort of proof step it was*)
quigley@15642
   342
(**************************************************************************************)
quigley@15642
   343
quigley@15642
   344
 fun follow_proof clauses allvars  clausenum thml  (Axiom ) clause_strs
quigley@15642
   345
        = follow_axiom clauses allvars  clausenum thml clause_strs
quigley@15642
   346
quigley@15642
   347
      | follow_proof clauses  allvars clausenum  thml (Binary (a, b)) clause_strs
quigley@15642
   348
        = follow_binary  (a, b)  allvars thml clause_strs
quigley@15642
   349
quigley@15642
   350
      | follow_proof clauses  allvars clausenum  thml (MRR (a, b)) clause_strs
quigley@15642
   351
        = follow_mrr (a, b)  allvars thml clause_strs
quigley@15642
   352
quigley@15642
   353
      | follow_proof clauses  allvars clausenum  thml (Factor (a, b, c)) clause_strs
quigley@15642
   354
         = follow_factor a b c  allvars thml clause_strs
quigley@15642
   355
quigley@15642
   356
      | follow_proof clauses  allvars clausenum  thml (Para (a, b)) clause_strs
quigley@15642
   357
        = follow_standard_para (a, b) allvars  thml clause_strs
quigley@15642
   358
quigley@15642
   359
      | follow_proof clauses  allvars clausenum thml (Rewrite (a,b)) clause_strs
quigley@15642
   360
        = follow_rewrite (a,b)  allvars thml clause_strs
quigley@15642
   361
quigley@15642
   362
      | follow_proof clauses  allvars clausenum thml (Obvious (a,b)) clause_strs
quigley@15642
   363
        = follow_obvious (a,b)  allvars thml clause_strs
quigley@15642
   364
quigley@15642
   365
      (*| follow_proof clauses  clausenum thml (Hyper l)
quigley@15642
   366
        = follow_hyper l thml*)
quigley@15642
   367
      | follow_proof clauses  allvars clausenum  thml _ _ =
quigley@15642
   368
          raise ASSERTION  "proof step not implemented"
quigley@15642
   369
quigley@15642
   370
quigley@15642
   371
quigley@15642
   372
 
quigley@15642
   373
(**************************************************************************************)
quigley@15642
   374
(* reconstruct a single line of the res. proof - at the moment do only inference steps*)
quigley@15642
   375
(**************************************************************************************)
quigley@15642
   376
quigley@15642
   377
    fun follow_line clauses  allvars thml (clause_num, proof_step, clause_strs) recons
quigley@15642
   378
        = let
quigley@15642
   379
            val (thm, recon_fun) = follow_proof clauses  allvars clause_num thml proof_step clause_strs 
quigley@15642
   380
            val recon_step = (recon_fun)
quigley@15642
   381
          in
quigley@15642
   382
            (((clause_num, thm)::thml), ((clause_num,recon_step)::recons))
quigley@15642
   383
          end
quigley@15642
   384
quigley@15642
   385
(***************************************************************)
quigley@15642
   386
(* follow through the res. proof, creating an Isabelle theorem *)
quigley@15642
   387
(***************************************************************)
quigley@15642
   388
quigley@15642
   389
quigley@15642
   390
quigley@15642
   391
(*fun is_proof_char ch = (case ch of 
quigley@15642
   392
                       
quigley@15642
   393
                        "(" => true
quigley@15642
   394
                       |  ")" => true
quigley@15642
   395
                         | ":" => true
quigley@15642
   396
                        |  "'" => true
quigley@15642
   397
                        |  "&" => true
quigley@15642
   398
                        | "|" => true
quigley@15642
   399
                        | "~" => true
quigley@15642
   400
                        |  "." => true
quigley@15642
   401
                        |(is_alpha ) => true
quigley@15642
   402
                       |(is_digit) => true
quigley@15642
   403
                         | _ => false)*)
quigley@15642
   404
quigley@15642
   405
fun is_proof_char ch = ((33 <= (ord ch)) andalso ((ord ch ) <= 126)) orelse (ch = " ")
quigley@15642
   406
quigley@15642
   407
fun proofstring x = let val exp = explode x 
quigley@15642
   408
                    in
quigley@15642
   409
                        List.filter (is_proof_char ) exp
quigley@15642
   410
                    end
quigley@15642
   411
quigley@15642
   412
quigley@15642
   413
fun not_newline ch = not (ch = "\n");
quigley@15642
   414
quigley@15642
   415
(*
quigley@15642
   416
quigley@15642
   417
fun follow clauses [] allvars thml recons = 
quigley@15642
   418
                             let (* val _ = reset show_sorts*)
paulson@15736
   419
                              val thmstring = Meson.concat_with_and (map string_of_thm (map snd thml))
quigley@15642
   420
                              val thmproofstring = proofstring ( thmstring)
quigley@15642
   421
                            val no_returns =List.filter  not_newline ( thmproofstring)
quigley@15642
   422
                            val thmstr = implode no_returns
quigley@15658
   423
                               val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "thml_file")))
quigley@15642
   424
                               val _ = TextIO.output(outfile, "thmstr is "^thmstr)
quigley@15642
   425
                               val _ = TextIO.flushOut outfile;
quigley@15642
   426
                               val _ =  TextIO.closeOut outfile
quigley@15642
   427
                                 (*val _ = set show_sorts*)
quigley@15642
   428
                             in
quigley@15642
   429
                                  ((snd( hd thml)), recons)
quigley@15642
   430
                             end
quigley@15642
   431
      | follow clauses (h::t) allvars thml recons 
quigley@15642
   432
        = let
quigley@15642
   433
            val (thml', recons') = follow_line clauses allvars  thml h recons
quigley@15642
   434
            val  (thm, recons_list) = follow clauses t  allvars thml' recons'
quigley@15642
   435
            
quigley@15642
   436
quigley@15642
   437
          in
quigley@15642
   438
             (thm,recons_list)
quigley@15642
   439
          end
quigley@15642
   440
quigley@15642
   441
*)
quigley@15642
   442
paulson@16061
   443
fun replace_clause_strs [] recons newrecons = (newrecons)
paulson@16061
   444
|   replace_clause_strs ((thmnum, thm)::thml)    
paulson@16061
   445
                  ((clausenum,(step,clause_strs,thmvars))::recons) newrecons = 
paulson@16061
   446
    let val new_clause_strs = ReconOrderClauses.get_meta_lits_bracket thm
paulson@16061
   447
    in
paulson@16061
   448
	replace_clause_strs thml recons  
paulson@16061
   449
	    ((clausenum,(step,new_clause_strs,thmvars))::newrecons)
paulson@16061
   450
    end
quigley@15642
   451
quigley@15642
   452
quigley@15642
   453
fun follow clauses [] allvars thml recons = 
paulson@16061
   454
      let 
paulson@16061
   455
	  val new_recons = replace_clause_strs thml recons []
paulson@16061
   456
      in
paulson@16061
   457
	   (#2(hd thml), new_recons)
paulson@16061
   458
      end
paulson@16061
   459
 | follow clauses (h::t) allvars thml recons =
paulson@16061
   460
      let
paulson@16061
   461
	val (thml', recons') = follow_line clauses allvars  thml h recons
paulson@16061
   462
	val  (thm, recons_list) = follow clauses t  allvars thml' recons'     
paulson@16061
   463
      in
paulson@16061
   464
	 (thm,recons_list)
paulson@16061
   465
      end
quigley@15642
   466
quigley@15642
   467
quigley@15642
   468
quigley@15642
   469
(* Assume we have the cnf clauses as a list of (clauseno, clause) *)
quigley@15642
   470
 (* and the proof as a list of the proper datatype *)
quigley@15642
   471
(* take the cnf clauses of the goal and the proof from the res. prover *)
quigley@15642
   472
(* as a list of type Proofstep and return the thm goal ==> False *)
quigley@15642
   473
quigley@15642
   474
fun first_pair (a,b,c) = (a,b);
quigley@15642
   475
quigley@15642
   476
fun second_pair (a,b,c) = (b,c);
quigley@15642
   477
quigley@15642
   478
(* takes original axioms, proof_steps parsed from spass, variables *)
quigley@15642
   479
quigley@15642
   480
fun translate_proof clauses proof allvars
quigley@15642
   481
        = let val (thm, recons) = follow clauses proof allvars [] []
quigley@15642
   482
          in
quigley@15642
   483
             (thm, (recons))
quigley@15642
   484
          end
quigley@15642
   485
  
quigley@15642
   486
quigley@15642
   487
quigley@15642
   488
fun remove_tinfo [] = []
paulson@16061
   489
  | remove_tinfo ( (clausenum, step, T_info, newstrs)::xs) =
paulson@16061
   490
      (clausenum, step , newstrs)::(remove_tinfo xs)