src/HOL/Tools/ATP/res_clasimpset.ML
author quigley
Tue, 31 May 2005 12:42:36 +0200
changeset 16156 2f6fc19aba1e
parent 16061 8a139c1557bf
child 16172 629ba53a072f
permissions -rw-r--r--
Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass ruleset.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
     1
15789
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15782
diff changeset
     2
(*  ID:         $Id$
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
     3
15789
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15782
diff changeset
     4
    Author:     Claire Quigley
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15782
diff changeset
     5
    Copyright   2004  University of Cambridge
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15782
diff changeset
     6
*)
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15782
diff changeset
     7
16156
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
     8
signature RES_CLASIMP = 
15919
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
     9
  sig
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
    10
     val write_out_clasimp :string -> (ResClause.clause * Thm.thm) Array.array * int
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
    11
  end;
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
    12
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
    13
structure ResClasimp : RES_CLASIMP =
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
    14
struct
15643
5829f30fc20a *** empty log message ***
quigley
parents:
diff changeset
    15
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    16
fun has_name th = ((Thm.name_of_thm th)  <>  "")
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    17
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    18
fun has_name_pair (a,b) = (a <> "");
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    19
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    20
15919
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
    21
(* changed, now it also finds out the name of the theorem. *)
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
    22
(* convert a theorem into CNF and then into Clause.clause format. *)
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    23
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    24
(* outputs a list of (thm,clause) pairs *)
15643
5829f30fc20a *** empty log message ***
quigley
parents:
diff changeset
    25
5829f30fc20a *** empty log message ***
quigley
parents:
diff changeset
    26
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    27
(* for tracing: encloses each string element in brackets. *)
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    28
fun concat_with_stop [] = ""
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    29
  | concat_with_stop [x] =  x
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    30
  | concat_with_stop (x::xs) = x^ "." ^ concat_with_stop xs;
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    31
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    32
fun remove_symb str = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    33
    if String.isPrefix  "List.op @." str
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    34
    then  ((String.substring(str,0,5)) ^ (String.extract (str, 10, NONE)))
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    35
    else str;
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    36
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    37
fun remove_spaces str = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    38
    let val strlist = String.tokens Char.isSpace str
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    39
	val spaceless = concat strlist
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    40
	val strlist' = String.tokens Char.isPunct spaceless
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    41
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    42
	concat_with_stop strlist'
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    43
    end
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    44
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    45
fun remove_symb_pair (str, thm) = (remove_symb str, thm);
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
    46
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    47
fun remove_spaces_pair (str, thm) = (remove_spaces str, thm);
15643
5829f30fc20a *** empty log message ***
quigley
parents:
diff changeset
    48
15956
0da64b5a9a00 theorem names for caching
paulson
parents: 15919
diff changeset
    49
0da64b5a9a00 theorem names for caching
paulson
parents: 15919
diff changeset
    50
(*Insert th into the result provided the name is not "".*)
0da64b5a9a00 theorem names for caching
paulson
parents: 15919
diff changeset
    51
fun add_nonempty ((name,th), ths) = if name="" then ths else th::ths;
0da64b5a9a00 theorem names for caching
paulson
parents: 15919
diff changeset
    52
16156
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    53
fun posinlist x [] n = "not in list"
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    54
|   posinlist x (y::ys) n = if (x=y) 
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    55
			    then
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    56
 				string_of_int n
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    57
			    else posinlist x (ys) (n+1)
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    58
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    59
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    60
fun pairup [] [] = []
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    61
|   pairup (x::xs) (y::ys) = (x,y)::(pairup xs ys)
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    62
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    63
fun multi x 0 xlist = xlist
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    64
   |multi x n xlist = multi x (n -1 ) (x::xlist);
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    65
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    66
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    67
fun clause_numbering ((clause, theorem), cls) = let val num_of_cls = length cls
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    68
                                              val numbers = 0 upto (num_of_cls -1)
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    69
                                              val multi_name = multi (clause, theorem)  num_of_cls []
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    70
                                          in 
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    71
                                              (multi_name)
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    72
                                          end;
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    73
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    74
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    75
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    76
 
15956
0da64b5a9a00 theorem names for caching
paulson
parents: 15919
diff changeset
    77
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    78
fun write_out_clasimp filename = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    79
    let val claset_rules = ResAxioms.claset_rules_of_thy (the_context());
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    80
	val named_claset = List.filter has_name_pair claset_rules;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    81
	val claset_names = map remove_spaces_pair (named_claset)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    82
	val claset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_claset []);
15643
5829f30fc20a *** empty log message ***
quigley
parents:
diff changeset
    83
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    84
	val simpset_rules = ResAxioms.simpset_rules_of_thy (the_context());
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    85
	val named_simpset = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    86
	      map remove_spaces_pair (List.filter has_name_pair simpset_rules)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    87
	val simpset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_simpset []);
15643
5829f30fc20a *** empty log message ***
quigley
parents:
diff changeset
    88
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    89
	val cls_thms = (claset_cls_thms@simpset_cls_thms);
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    90
	val cls_thms_list = List.concat cls_thms;
16156
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    91
        (* length 1429 *)
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    92
	(*************************************************)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    93
	(* Write out clauses as tptp strings to filename *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    94
	(*************************************************)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    95
	val clauses = map #1(cls_thms_list);
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
    96
	val cls_tptp_strs = map ResClause.tptp_clause clauses;
16156
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    97
        val alllist = pairup cls_thms_list cls_tptp_strs
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    98
        val whole_list = List.concat (map clause_numbering alllist);
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
    99
 
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   100
        (*********************************************************)
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   101
	(* create array and put clausename, number pairs into it *)
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   102
	(*********************************************************)
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   103
	val num_of_clauses =  0;
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   104
	val clause_arr = Array.fromList whole_list;
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   105
	val num_of_clauses = List.length whole_list;
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   106
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   107
	(* list of lists of tptp string clauses *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   108
	val stick_clasrls =   List.concat cls_tptp_strs;
16156
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   109
        (* length 1581*)
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   110
	val out = TextIO.openOut filename;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   111
	val _=   ResLib.writeln_strs out stick_clasrls;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   112
	val _= TextIO.flushOut out;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   113
	val _= TextIO.closeOut out
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   114
  in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   115
	(clause_arr, num_of_clauses)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 16039
diff changeset
   116
  end;
15643
5829f30fc20a *** empty log message ***
quigley
parents:
diff changeset
   117
15919
b30a35432f5a Replaced reference to SPASS with general one - set SPASS_HOME in settings file.
quigley
parents: 15907
diff changeset
   118
end;
16039
dfe264950511 Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents: 15956
diff changeset
   119
16156
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   120
2f6fc19aba1e Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents: 16061
diff changeset
   121