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.
paulson@15789
     1
(*  ID:         $Id$
paulson@15789
     2
    Author:     Claire Quigley
paulson@15789
     3
    Copyright   2004  University of Cambridge
paulson@15789
     4
*)
paulson@15789
     5
quigley@15919
     6
signature RES_CLASIMP =
quigley@15919
     7
  sig
quigley@15919
     8
     val write_out_clasimp :string -> (ResClause.clause * Thm.thm) Array.array * int
quigley@15919
     9
  end;
quigley@15919
    10
quigley@15919
    11
structure ResClasimp : RES_CLASIMP =
quigley@15919
    12
struct
quigley@15643
    13
quigley@15643
    14
fun has_name th = not((Thm.name_of_thm th)= "")
quigley@15643
    15
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@15919
    21
(* changed, now it also finds out the name of the theorem. *)
quigley@15919
    22
(* convert a theorem into CNF and then into Clause.clause format. *)
quigley@15919
    23
fun clausify_axiom_pairs thm =
quigley@15919
    24
    let val isa_clauses = ResAxioms.cnf_axiom thm (*"isa_clauses" are already "standard"ed. *)
quigley@15919
    25
        val isa_clauses' = ResAxioms.rm_Eps [] isa_clauses
quigley@15919
    26
        val thm_name = Thm.name_of_thm thm
quigley@15919
    27
	val clauses_n = length isa_clauses
quigley@15919
    28
	fun make_axiom_clauses _ [] []= []
quigley@15919
    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'
quigley@15919
    30
    in
quigley@15919
    31
	make_axiom_clauses 0 isa_clauses' isa_clauses		
quigley@15919
    32
    end;
quigley@15643
    33
quigley@15643
    34
quigley@15919
    35
fun clausify_rules_pairs [] err_list = ([],err_list)
quigley@15919
    36
  | clausify_rules_pairs (thm::thms) err_list =
quigley@15919
    37
    let val (ts,es) = clausify_rules_pairs thms err_list
quigley@15919
    38
    in
quigley@15919
    39
	((clausify_axiom_pairs thm)::ts,es) handle  _ => (ts,(thm::es))
quigley@15919
    40
    end;
quigley@15643
    41
quigley@15919
    42
fun write_out_clasimp filename = let
quigley@15919
    43
					val claset_rules = ResAxioms.claset_rules_of_thy (the_context());
quigley@15919
    44
					val named_claset = List.filter has_name claset_rules;
quigley@15919
    45
					val claset_cls_thms = #1( clausify_rules_pairs named_claset []);
quigley@15643
    46
quigley@15919
    47
					val simpset_rules = ResAxioms.simpset_rules_of_thy (the_context());
quigley@15919
    48
					val named_simpset = map #2(List.filter has_name_pair simpset_rules);
quigley@15919
    49
					val simpset_cls_thms = #1 (clausify_rules_pairs named_simpset []);
quigley@15643
    50
quigley@15919
    51
					val cls_thms = (claset_cls_thms@simpset_cls_thms);
quigley@15919
    52
					val cls_thms_list = stick cls_thms;
quigley@15643
    53
quigley@15919
    54
                                        (*********************************************************)
quigley@15919
    55
                                  	(* create array and put clausename, number pairs into it *)
quigley@15919
    56
                                   	(*********************************************************)
quigley@15919
    57
					val num_of_clauses =  0;
quigley@15919
    58
                                     	val clause_arr = Array.fromList cls_thms_list;
quigley@15919
    59
              
quigley@15919
    60
                                   	val  num_of_clauses= (List.length cls_thms_list);
quigley@15782
    61
quigley@15919
    62
                                        (*************************************************)
quigley@15919
    63
					(* Write out clauses as tptp strings to filename *)
quigley@15919
    64
 					(*************************************************)
quigley@15919
    65
                                        val clauses = map #1(cls_thms_list);
quigley@15919
    66
          				val cls_tptp_strs = map ResClause.tptp_clause clauses;
quigley@15919
    67
                                        (* list of lists of tptp string clauses *)
quigley@15919
    68
                                        val stick_clasrls =   stick cls_tptp_strs;
quigley@15919
    69
    					val out = TextIO.openOut filename;
quigley@15919
    70
                                    	val _=   ResLib.writeln_strs out stick_clasrls;
quigley@15919
    71
                                    	val _= TextIO.flushOut out;
quigley@15919
    72
					val _= TextIO.closeOut out
quigley@15919
    73
                     		  in
quigley@15919
    74
					(clause_arr, num_of_clauses)
quigley@15919
    75
				  end;
quigley@15643
    76
quigley@15643
    77
quigley@15919
    78
end;