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