src/HOL/Tools/ATP/res_clasimpset.ML
author quigley
Mon May 23 00:18:51 2005 +0200 (2005-05-23)
changeset 16039 dfe264950511
parent 15956 0da64b5a9a00
child 16061 8a139c1557bf
permissions -rw-r--r--
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
Changed watcher.ML so that the Unix.execute and Unix.reap functions are used instead of those in modUnix.ML, and
consequently removed modUnix.ML from Reconstruction.thy
quigley@16039
     1
paulson@15789
     2
(*  ID:         $Id$
quigley@16039
     3
paulson@15789
     4
    Author:     Claire Quigley
paulson@15789
     5
    Copyright   2004  University of Cambridge
paulson@15789
     6
*)
paulson@15789
     7
quigley@15919
     8
signature RES_CLASIMP =
quigley@15919
     9
  sig
quigley@15919
    10
     val write_out_clasimp :string -> (ResClause.clause * Thm.thm) Array.array * int
quigley@15919
    11
  end;
quigley@15919
    12
quigley@15919
    13
structure ResClasimp : RES_CLASIMP =
quigley@15919
    14
struct
quigley@16039
    15
fun has_name th = not((Thm.name_of_thm th )= "")
quigley@15643
    16
fun has_name_pair (a,b) = not_equal a "";
quigley@15643
    17
quigley@15643
    18
fun stick []  = []
quigley@15643
    19
|   stick (x::xs)  = x@(stick xs )
quigley@15643
    20
quigley@16039
    21
fun filterlist p [] = []
quigley@16039
    22
|   filterlist p (x::xs) = if p x 
quigley@16039
    23
                           then 
quigley@16039
    24
                               (x::(filterlist p xs))
quigley@16039
    25
                           else
quigley@16039
    26
                               filterlist p xs
quigley@16039
    27
quigley@16039
    28
quigley@15919
    29
(* changed, now it also finds out the name of the theorem. *)
quigley@15919
    30
(* convert a theorem into CNF and then into Clause.clause format. *)
quigley@16039
    31
quigley@16039
    32
(* outputs a list of (thm,clause) pairs *)
quigley@15643
    33
quigley@15643
    34
quigley@16039
    35
(* for tracing: encloses each string element in brackets. *)
quigley@16039
    36
fun concat_with_stop [] = ""
quigley@16039
    37
  | concat_with_stop [x] =  x
quigley@16039
    38
  | concat_with_stop (x::xs) = x^ "." ^ concat_with_stop xs;
quigley@16039
    39
quigley@16039
    40
fun remove_symb str = if String.isPrefix  "List.op @." str
quigley@16039
    41
                      then 
quigley@16039
    42
                          ((String.substring(str,0,5))^(String.extract (str, 10, NONE)))
quigley@16039
    43
                      else
quigley@16039
    44
                          str
quigley@16039
    45
quigley@16039
    46
fun remove_spaces str = let val strlist = String.tokens Char.isSpace str
quigley@16039
    47
                            val spaceless = concat strlist
quigley@16039
    48
                            val strlist' = String.tokens Char.isPunct spaceless
quigley@16039
    49
                        in
quigley@16039
    50
                            concat_with_stop strlist'
quigley@16039
    51
                        end
quigley@16039
    52
quigley@16039
    53
fun remove_symb_pair (str, thm) = let val newstr = remove_symb str
quigley@16039
    54
                                  in
quigley@16039
    55
                                    (newstr, thm)
quigley@16039
    56
                                  end
quigley@16039
    57
quigley@16039
    58
quigley@16039
    59
fun remove_spaces_pair (str, thm) = let val newstr = remove_spaces str
quigley@16039
    60
                                  in
quigley@16039
    61
                                    (newstr, thm)
quigley@16039
    62
                                  end
quigley@16039
    63
quigley@16039
    64
quigley@15643
    65
paulson@15956
    66
paulson@15956
    67
(*Insert th into the result provided the name is not "".*)
paulson@15956
    68
fun add_nonempty ((name,th), ths) = if name="" then ths else th::ths;
paulson@15956
    69
paulson@15956
    70
quigley@15919
    71
fun write_out_clasimp filename = let
quigley@15919
    72
					val claset_rules = ResAxioms.claset_rules_of_thy (the_context());
quigley@16039
    73
					val named_claset = filterlist has_name_pair claset_rules;
quigley@16039
    74
					val claset_names = map remove_spaces_pair (named_claset)
quigley@16039
    75
					val claset_cls_thms = #1( ResAxioms.clausify_rules_pairs named_claset []);
quigley@16039
    76
quigley@15643
    77
quigley@15919
    78
					val simpset_rules = ResAxioms.simpset_rules_of_thy (the_context());
quigley@16039
    79
					val named_simpset = map remove_spaces_pair (filterlist has_name_pair simpset_rules);
quigley@16039
    80
					val simpset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_simpset []);
quigley@15643
    81
quigley@15919
    82
					val cls_thms = (claset_cls_thms@simpset_cls_thms);
quigley@15919
    83
					val cls_thms_list = stick cls_thms;
quigley@15643
    84
quigley@15919
    85
                                        (*********************************************************)
quigley@15919
    86
                                  	(* create array and put clausename, number pairs into it *)
quigley@15919
    87
                                   	(*********************************************************)
quigley@15919
    88
					val num_of_clauses =  0;
quigley@15919
    89
                                     	val clause_arr = Array.fromList cls_thms_list;
quigley@15919
    90
              
quigley@15919
    91
                                   	val  num_of_clauses= (List.length cls_thms_list);
quigley@15782
    92
quigley@15919
    93
                                        (*************************************************)
quigley@15919
    94
					(* Write out clauses as tptp strings to filename *)
quigley@15919
    95
 					(*************************************************)
quigley@15919
    96
                                        val clauses = map #1(cls_thms_list);
quigley@15919
    97
          				val cls_tptp_strs = map ResClause.tptp_clause clauses;
quigley@15919
    98
                                        (* list of lists of tptp string clauses *)
quigley@15919
    99
                                        val stick_clasrls =   stick cls_tptp_strs;
quigley@15919
   100
    					val out = TextIO.openOut filename;
quigley@15919
   101
                                    	val _=   ResLib.writeln_strs out stick_clasrls;
quigley@15919
   102
                                    	val _= TextIO.flushOut out;
quigley@15919
   103
					val _= TextIO.closeOut out
quigley@15919
   104
                     		  in
quigley@15919
   105
					(clause_arr, num_of_clauses)
quigley@15919
   106
				  end;
quigley@15643
   107
quigley@15643
   108
quigley@15919
   109
end;
quigley@16039
   110