src/HOL/Tools/ATP/res_clasimpset.ML
author quigley
Tue May 03 14:27:21 2005 +0200 (2005-05-03)
changeset 15919 b30a35432f5a
parent 15907 f377ba412dba
child 15956 0da64b5a9a00
permissions -rw-r--r--
Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
Rewrote res_clasimpset.ML. Now produces an array of (thm, clause) in addition to writing out clasimpset as tptp strings. C.Q.
     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 th = not((Thm.name_of_thm th)= "")
    15 
    16 fun has_name_pair (a,b) = not_equal a "";
    17 
    18 fun stick []  = []
    19 |   stick (x::xs)  = x@(stick xs )
    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 fun clausify_axiom_pairs thm =
    24     let val isa_clauses = ResAxioms.cnf_axiom thm (*"isa_clauses" are already "standard"ed. *)
    25         val isa_clauses' = ResAxioms.rm_Eps [] isa_clauses
    26         val thm_name = Thm.name_of_thm thm
    27 	val clauses_n = length isa_clauses
    28 	fun make_axiom_clauses _ [] []= []
    29 	  | make_axiom_clauses i (cls::clss) (cls'::clss')= ((ResClause.make_axiom_clause cls (thm_name,i)),cls') :: make_axiom_clauses (i+1) clss clss'
    30     in
    31 	make_axiom_clauses 0 isa_clauses' isa_clauses		
    32     end;
    33 
    34 
    35 fun clausify_rules_pairs [] err_list = ([],err_list)
    36   | clausify_rules_pairs (thm::thms) err_list =
    37     let val (ts,es) = clausify_rules_pairs thms err_list
    38     in
    39 	((clausify_axiom_pairs thm)::ts,es) handle  _ => (ts,(thm::es))
    40     end;
    41 
    42 fun write_out_clasimp filename = let
    43 					val claset_rules = ResAxioms.claset_rules_of_thy (the_context());
    44 					val named_claset = List.filter has_name claset_rules;
    45 					val claset_cls_thms = #1( clausify_rules_pairs named_claset []);
    46 
    47 					val simpset_rules = ResAxioms.simpset_rules_of_thy (the_context());
    48 					val named_simpset = map #2(List.filter has_name_pair simpset_rules);
    49 					val simpset_cls_thms = #1 (clausify_rules_pairs named_simpset []);
    50 
    51 					val cls_thms = (claset_cls_thms@simpset_cls_thms);
    52 					val cls_thms_list = stick cls_thms;
    53 
    54                                         (*********************************************************)
    55                                   	(* create array and put clausename, number pairs into it *)
    56                                    	(*********************************************************)
    57 					val num_of_clauses =  0;
    58                                      	val clause_arr = Array.fromList cls_thms_list;
    59               
    60                                    	val  num_of_clauses= (List.length cls_thms_list);
    61 
    62                                         (*************************************************)
    63 					(* Write out clauses as tptp strings to filename *)
    64  					(*************************************************)
    65                                         val clauses = map #1(cls_thms_list);
    66           				val cls_tptp_strs = map ResClause.tptp_clause clauses;
    67                                         (* list of lists of tptp string clauses *)
    68                                         val stick_clasrls =   stick cls_tptp_strs;
    69     					val out = TextIO.openOut filename;
    70                                     	val _=   ResLib.writeln_strs out stick_clasrls;
    71                                     	val _= TextIO.flushOut out;
    72 					val _= TextIO.closeOut out
    73                      		  in
    74 					(clause_arr, num_of_clauses)
    75 				  end;
    76 
    77 
    78 end;