src/HOL/Tools/ATP/res_clasimpset.ML
author paulson
Thu May 12 18:24:42 2005 +0200 (2005-05-12)
changeset 15956 0da64b5a9a00
parent 15919 b30a35432f5a
child 16039 dfe264950511
permissions -rw-r--r--
theorem names for caching
     1 (*  ID:         $Id$
     2     Author:     Claire Quigley
     3     Copyright   2004  University of Cambridge
     4 *)
     5 
     6 signature RES_CLASIMP =
     7   sig
     8      val write_out_clasimp :string -> (ResClause.clause * Thm.thm) Array.array * int
     9   end;
    10 
    11 structure ResClasimp : RES_CLASIMP =
    12 struct
    13 
    14 fun has_name_pair (a,b) = not_equal a "";
    15 
    16 fun stick []  = []
    17 |   stick (x::xs)  = x@(stick xs )
    18 
    19 (* changed, now it also finds out the name of the theorem. *)
    20 (* convert a theorem into CNF and then into Clause.clause format. *)
    21 fun clausify_axiom_pairs thm =
    22     let val thm_name = Thm.name_of_thm thm
    23 	val isa_clauses = ResAxioms.cnf_axiom (thm_name,thm) (*"isa_clauses" are already "standard"ed. *)
    24         val isa_clauses' = ResAxioms.rm_Eps [] isa_clauses
    25         val clauses_n = length isa_clauses
    26 	fun make_axiom_clauses _ [] []= []
    27 	  | make_axiom_clauses i (cls::clss) (cls'::clss')= ((ResClause.make_axiom_clause cls (thm_name,i)),cls') :: make_axiom_clauses (i+1) clss clss'
    28     in
    29 	make_axiom_clauses 0 isa_clauses' isa_clauses		
    30     end;
    31 
    32 
    33 fun clausify_rules_pairs [] err_list = ([],err_list)
    34   | clausify_rules_pairs (thm::thms) err_list =
    35     let val (ts,es) = clausify_rules_pairs thms err_list
    36     in
    37 	((clausify_axiom_pairs thm)::ts,es) handle  _ => (ts,(thm::es))
    38     end;
    39 
    40 
    41 (*Insert th into the result provided the name is not "".*)
    42 fun add_nonempty ((name,th), ths) = if name="" then ths else th::ths;
    43 
    44 
    45 fun write_out_clasimp filename = let
    46 					val claset_rules = ResAxioms.claset_rules_of_thy (the_context());
    47 					val named_claset = List.foldr add_nonempty []  claset_rules;
    48 					val claset_cls_thms = #1( clausify_rules_pairs named_claset []);
    49 
    50 					val simpset_rules = ResAxioms.simpset_rules_of_thy (the_context());
    51 					val named_simpset = map #2(List.filter has_name_pair simpset_rules);
    52 					val simpset_cls_thms = #1 (clausify_rules_pairs named_simpset []);
    53 
    54 					val cls_thms = (claset_cls_thms@simpset_cls_thms);
    55 					val cls_thms_list = stick cls_thms;
    56 
    57                                         (*********************************************************)
    58                                   	(* create array and put clausename, number pairs into it *)
    59                                    	(*********************************************************)
    60 					val num_of_clauses =  0;
    61                                      	val clause_arr = Array.fromList cls_thms_list;
    62               
    63                                    	val  num_of_clauses= (List.length cls_thms_list);
    64 
    65                                         (*************************************************)
    66 					(* Write out clauses as tptp strings to filename *)
    67  					(*************************************************)
    68                                         val clauses = map #1(cls_thms_list);
    69           				val cls_tptp_strs = map ResClause.tptp_clause clauses;
    70                                         (* list of lists of tptp string clauses *)
    71                                         val stick_clasrls =   stick cls_tptp_strs;
    72     					val out = TextIO.openOut filename;
    73                                     	val _=   ResLib.writeln_strs out stick_clasrls;
    74                                     	val _= TextIO.flushOut out;
    75 					val _= TextIO.closeOut out
    76                      		  in
    77 					(clause_arr, num_of_clauses)
    78 				  end;
    79 
    80 
    81 end;