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