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
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_pair (a,b) = not_equal a "";
quigley@15643
    15
quigley@15643
    16
fun stick []  = []
quigley@15643
    17
|   stick (x::xs)  = x@(stick xs )
quigley@15643
    18
quigley@15919
    19
(* changed, now it also finds out the name of the theorem. *)
quigley@15919
    20
(* convert a theorem into CNF and then into Clause.clause format. *)
quigley@15919
    21
fun clausify_axiom_pairs thm =
paulson@15956
    22
    let val thm_name = Thm.name_of_thm thm
paulson@15956
    23
	val isa_clauses = ResAxioms.cnf_axiom (thm_name,thm) (*"isa_clauses" are already "standard"ed. *)
quigley@15919
    24
        val isa_clauses' = ResAxioms.rm_Eps [] isa_clauses
paulson@15956
    25
        val clauses_n = length isa_clauses
quigley@15919
    26
	fun make_axiom_clauses _ [] []= []
quigley@15919
    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'
quigley@15919
    28
    in
quigley@15919
    29
	make_axiom_clauses 0 isa_clauses' isa_clauses		
quigley@15919
    30
    end;
quigley@15643
    31
quigley@15643
    32
quigley@15919
    33
fun clausify_rules_pairs [] err_list = ([],err_list)
quigley@15919
    34
  | clausify_rules_pairs (thm::thms) err_list =
quigley@15919
    35
    let val (ts,es) = clausify_rules_pairs thms err_list
quigley@15919
    36
    in
quigley@15919
    37
	((clausify_axiom_pairs thm)::ts,es) handle  _ => (ts,(thm::es))
quigley@15919
    38
    end;
quigley@15643
    39
paulson@15956
    40
paulson@15956
    41
(*Insert th into the result provided the name is not "".*)
paulson@15956
    42
fun add_nonempty ((name,th), ths) = if name="" then ths else th::ths;
paulson@15956
    43
paulson@15956
    44
quigley@15919
    45
fun write_out_clasimp filename = let
quigley@15919
    46
					val claset_rules = ResAxioms.claset_rules_of_thy (the_context());
paulson@15956
    47
					val named_claset = List.foldr add_nonempty []  claset_rules;
quigley@15919
    48
					val claset_cls_thms = #1( clausify_rules_pairs named_claset []);
quigley@15643
    49
quigley@15919
    50
					val simpset_rules = ResAxioms.simpset_rules_of_thy (the_context());
quigley@15919
    51
					val named_simpset = map #2(List.filter has_name_pair simpset_rules);
quigley@15919
    52
					val simpset_cls_thms = #1 (clausify_rules_pairs named_simpset []);
quigley@15643
    53
quigley@15919
    54
					val cls_thms = (claset_cls_thms@simpset_cls_thms);
quigley@15919
    55
					val cls_thms_list = stick cls_thms;
quigley@15643
    56
quigley@15919
    57
                                        (*********************************************************)
quigley@15919
    58
                                  	(* create array and put clausename, number pairs into it *)
quigley@15919
    59
                                   	(*********************************************************)
quigley@15919
    60
					val num_of_clauses =  0;
quigley@15919
    61
                                     	val clause_arr = Array.fromList cls_thms_list;
quigley@15919
    62
              
quigley@15919
    63
                                   	val  num_of_clauses= (List.length cls_thms_list);
quigley@15782
    64
quigley@15919
    65
                                        (*************************************************)
quigley@15919
    66
					(* Write out clauses as tptp strings to filename *)
quigley@15919
    67
 					(*************************************************)
quigley@15919
    68
                                        val clauses = map #1(cls_thms_list);
quigley@15919
    69
          				val cls_tptp_strs = map ResClause.tptp_clause clauses;
quigley@15919
    70
                                        (* list of lists of tptp string clauses *)
quigley@15919
    71
                                        val stick_clasrls =   stick cls_tptp_strs;
quigley@15919
    72
    					val out = TextIO.openOut filename;
quigley@15919
    73
                                    	val _=   ResLib.writeln_strs out stick_clasrls;
quigley@15919
    74
                                    	val _= TextIO.flushOut out;
quigley@15919
    75
					val _= TextIO.closeOut out
quigley@15919
    76
                     		  in
quigley@15919
    77
					(clause_arr, num_of_clauses)
quigley@15919
    78
				  end;
quigley@15643
    79
quigley@15643
    80
quigley@15919
    81
end;